Reputation: 2846
I've got a bit of a weird question for a temporary fix we're putting into our app. For terrible reasons, we have a segmented control with three segments, but we have three instances of each segmented control inside of three tableView data sources (don't ask, we're hoping this isn't the final solution...)
Anyway, because of this awful setup, when we select a new segment, instance A of the segmented control gets it's new index selected. We then swap out data sources and call reloadData
on the table. Now we have instance B of the segmented control with the same index as instance A selected. When we then select the original segment, instance B gets its index set to the new index, and we now reload data, which causes instance A to be shown. Instance A, however, still has the old index selected, and so it's selection shows the wrong index.
I'm currently solving this by manually resetting the selected index in the delegate callback for a tap. However, what would be ideal, would be to tell the segmented control that I don't want it to change it's selection, but I do still want users to be able to interact with it. Is that possible at all? I realize this is a terrible solution, again, we hope to change it in the future, so for now, any suggestions for me?
Upvotes: 0
Views: 128
Reputation: 131491
In the final step, when instance A of the segmented control gets shown again, you should write your cellForRowAtIndexPath to set the segment to the desired segment using the selectedSegmentIndex
property. That way when instance A is displayed again it will show the correct index.
Upvotes: 1