sumderungHAY
sumderungHAY

Reputation: 1337

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.

Upvotes: 6

Views: 9014

Answers (2)

Mugunth
Mugunth

Reputation: 14509

You can use the addTarget:action:forControlEvents method.

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

Upvotes: 4

Deepak Danduprolu
Deepak Danduprolu

Reputation: 44633

Attach a target-action for the control event UIControlEventValueChanged.

Example

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

Upvotes: 17

Related Questions