UISegmentedControl value changed programmatically

How can I connect my modified UISegmentedControl method programmatically. I know this is possible using IB, but I was wondering how to do this with code. Thanks.

+6
source share
2 answers

Attach the target action for the UIControlEventValueChanged control UIControlEventValueChanged .

Example

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

You can use the addTarget: action: forControlEvents method.

 UISegmentControl *mySegmentedControl = [UISegmentControl ...]; [mySegmentedControl addTarget:self action:@selector(segmentValueChanged:) forControlEvents:UIControlEventValueChanged]; 
+4
source

Source: https://habr.com/ru/post/892819/


All Articles