I'm looking at this question and wondering how it was known or where it is documented that [[segmentedControl subviews] objectAtIndex:0]
is the currently selected control segment?
That is - how do we know which objectAtIndex
number to use?
I'm looking at this question and wondering how it was known or where it is documented that [[segmentedControl subviews] objectAtIndex:0]
is the currently selected control segment?
That is - how do we know which objectAtIndex
number to use?
If you look at other responses, you see that they look for the one that is selected, that is, check what isSelected
returns
for (int i = 0; i < [sender.subviews count]; i++)
{
if ([[sender.subviews objectAtIndex:i]isSelected])
{
...
}
}
I have to say that the code Frowing mentioned may crash. class checking is needed.
for (int i = 0; i < [sender.subviews count]; i++) {
UIView *seg = [sender.subviews objectAtIndex:i];
if ([seg isKindOfClass:[UISegmentedControl class]]&&[seg isSelected])
{
...
}
}