Search code examples
iphoneobjective-cioscocoa-touchuisegmentedcontrol

UISegmentedControl value changed programmatically


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.


Solution

  • Attach a target-action for the control event UIControlEventValueChanged.

    Example

    [segmentedControl addTarget:self action:@selector(valueChanged:) forControlEvents: UIControlEventValueChanged];