开发者

UISegmentedControl and registering callback without XIB

开发者 https://www.devze.com 2023-02-15 11:37 出处:网络
I have added a UISegmented control as follows (this seems to work just fine, but let me know if this is a bad practice):

I have added a UISegmented control as follows (this seems to work just fine, but let me know if this is a bad practice):

mapType = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects: @"Map", @"Satelitte", @"Hybrid", nil]];    
[_mapView addSubview:mapType];

Then I have a method that I would like to be called when this UISegmentedControl is changed, however, I cannot set the delegate or anything in the interface builder because I am doing this programmatically.

- (void)segmentedChangedType {
/开发者_JAVA技巧/ some code here
}

How can I connect these? Thanks in advance for any help!

If the only solution is to use XIB, then I can do that, but would like to know how to do this if it's possible.


OK, figured it out, you add this:

[mapType addTarget:self action:@selector(changeType) forControlEvents:UIControlEventValueChanged];
0

精彩评论

暂无评论...
验证码 换一张
取 消