Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 390
sumderungHAY Avatar asked Jul 15 '11 09:07

sumderungHAY


2 Answers

Attach a target-action for the control event UIControlEventValueChanged.

Example

[segmentedControl addTarget:self action:@selector(valueChanged:) forControlEvents: UIControlEventValueChanged];
like image 184
Deepak Danduprolu Avatar answered Oct 23 '22 22:10

Deepak Danduprolu


You can use the addTarget:action:forControlEvents method.

UISegmentControl *mySegmentedControl = [UISegmentControl ...];
[mySegmentedControl addTarget:self action:@selector(segmentValueChanged:) forControlEvents:UIControlEventValueChanged];
like image 25
Mugunth Avatar answered Oct 24 '22 00:10

Mugunth