Reputation: 1337
How can I hook up my UISegmentedControl's value changed method programmatically. I know it's possible using IB but I was wondering how to do it with code. Thanks.
Upvotes: 6
Views: 9014
Reputation: 14509
You can use the addTarget:action:forControlEvents method.
UISegmentControl *mySegmentedControl = [UISegmentControl ...];
[mySegmentedControl addTarget:self action:@selector(segmentValueChanged:) forControlEvents:UIControlEventValueChanged];
Upvotes: 4
Reputation: 44633
Attach a target-action for the control event UIControlEventValueChanged
.
Example
[segmentedControl addTarget:self action:@selector(valueChanged:) forControlEvents: UIControlEventValueChanged];
Upvotes: 17