Resetting / Reloading UISegmentedControl

Thought of sharing as quick google didn’t land me to the solution. If you want to reset the UISegmentedControl to a state where nothing is selected (this was the requirement for me), then you just need to set its ‘selectedIndex’ to -1. Reminds of C (EOF character = -1 :)). Here is the snippet I wrote on click of reset button:-


NSArray *segmentedControls = [NSArray arrayWithObjects : roadTestConducted, validVehicle];

for(UISegmentedControl *segControl in segmentedControls) {

[segControl setSelectedSegmentedIndex:-1];
}

Hope one finds this useful

Advertisements

2 thoughts on “Resetting / Reloading UISegmentedControl

  1. Thank you so much! I would not have guessed this in a million years. It works like a charm. I was expecting to have to play around with the momentary flag, which would have been no fun at all.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s