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.
Asked
Active
Viewed 9,008 times
2 Answers
17
Attach a target-action for the control event UIControlEventValueChanged
.
Example
[segmentedControl addTarget:self action:@selector(valueChanged:) forControlEvents: UIControlEventValueChanged];

Deepak Danduprolu
- 44,595
- 12
- 101
- 105
4
You can use the addTarget:action:forControlEvents method.
UISegmentControl *mySegmentedControl = [UISegmentControl ...];
[mySegmentedControl addTarget:self action:@selector(segmentValueChanged:) forControlEvents:UIControlEventValueChanged];

EmptyStack
- 51,274
- 23
- 147
- 178

Mugunth
- 14,461
- 15
- 66
- 94