I am in UIApplication::sendEvent override. I get a UIEvent which ultimately gives me UITouch object. When UITouch has phase == 3 (touch phase ended or touch up), I try to identify if the UITouch's view object was UISegmentedControl or not. If yes, I try to get selectedSegmentIndex. At this point and time I always get wrong value(or previous value of selectedSegmentIndex).
Is it that, this value is changed only after its action method is executed? Or What do I need to do to get the latest value of selectedSegmentIndex.
Any help appreciated.
- (void)sendEvent:(UIEvent *)event
{
[super sendEvent:event];
NSSet *touches = [event allTouches];
NSEnumerator *enumerator = [touches objectEnumerator];
id value;
while ((value = [enumerator nextObject])) {
UITouch *touch = value;
if (touch.phase==3) {
if([touch.view isKindOfClass:[UISegmentedControl class]])
{
UISegmentedControl *sc = (UISegmentedControl*)touch.view;
NSLog(@"%d",[sc selectedSegmentIndex]);
}
}
}
}