Search code examples
objective-cios7uisegmentedcontrol

How to make a single UISegmentedControl section detect multiple touches


I am using a UISegmentedControl section to show an action sheet when pressed. The action sheet has 2 date pickers one to set a from date and one to set a to date.

When the action sheet is finished with it hides away and does what it needs to do, however I have noticed that the only way to get the action sheet back up is by selecting the another section of the UISegment and then to select the segment that shows the action sheet.

My question is, are there any methods of responding to another touch event on a specific segment of a UISegmentedControl that has already been selected?

I have already used selectedSegmentIndex in the code to show the action sheet.

Thanks in advance.


Solution

  • Sounds like what you're looking for is the momentary state for your UISegmentControl. This will be prevent the segment control from holding a selected position for any segment. Tapping a segment will act as a button instead of a tab-like selector.

    You can do this in interface builder like so:

    Segment Control options

    Or you can do it in code:

    segmentControl.momentary = YES
    

    This solution will work if you don't need the segment control to show the currently selected segment. From your description, this seems fitting.