UISegmentedControl register taps on selected segment

后端 未结 20 3069
渐次进展
渐次进展 2020-12-04 15:28

I have a segmented control where the user can select how to order a list. Works fine.

However, I would like that when an already selected segment is tapped, the orde

20条回答
  •  一向
    一向 (楼主)
    2020-12-04 15:50

    The current solution presented still does not work, because setSelectedSegmentIndex is never called unless really a new segment is tapped. At least in my case this never worked, I do use iOS5 though, perhaps this solution did work in iOS4. Anyway, this is my solution. It needs one extra subclass method, which is the following:

    -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {    
        [self setSelectedSegmentIndex:self.selectedSegmentIndex];
        [super touchesEnded:touches withEvent:event];
    }
    

    Good luck!

提交回复
热议问题