UISegmentedControl and registering callback without XIB
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];
精彩评论