UISegmentedControl setSelectedSegmentIndex: without valueChanged Action
Your question is a sensible one; I can only suggest that you've found a bug, since this is so unusual. Usually, changing a control in code doesn't cause any control events to be emitted. Setting a UIDatePicker's date
doesn't emit a Value Changed event. Setting a UIPageControl's currentPage
doesn't emit a Value Changed event. Setting a UISlider's value
doesn't emit a Value Changed event. Setting a UISwitch's on
doesn't emit a Value Changed event. Similarly, setting a UITextField's text
doesn't emit an Editing Changed event. So, the fact that changing a UISegmentedControl's selectedSegmentIndex
emits a Value Changed event feels wrong. I'm going to file a bug and I think you should too.
I don't see an obvious way to determine whether the Value Changed event was triggered by the user tapping or programmatically. You'll have to raise and lower a BOOL flag or something.
EDIT: This is fixed in iOS 5.