I have a UIViewController that has a UITableView and a UISegmentedControl with 4 segments in it. Each time the user clicks on another segment, the type of cells displayed in the table view should change. For this, I have the following code:
- (IBAction)segmentedControlChanged:(UISegmentedControl *)sender { [self.tableView reloadData]; }
Typically, the third segment fills the table view with the largest number of cells. So, while on the third segment, when I look at the bottom of the table and then switch to another segment, I expect the table view to simply reload its cells and stay in the same scroll position. However, what happens is that the title view is apparently located at the bottom of the screen, as if the table view had been scrolled to the top to its limits. Then, when I touch and start scrolling again, everything returns to its normal state, as if the table simply scrolled down and cells appeared.
I tried to solve this problem for a while, and the messages I have seen so far have all offered the same thing. They said that if the animation is being processed in a thread of another main thread, this type of problem is inevitable. So I tried to change the code as shown below:
- (IBAction)segmentedControlChanged:(UISegmentedControl *)sender { dispatch_async(dispatch_get_main_queue(), ^{ [self.tableView reloadData]; }); }
and
- (IBAction)segmentedControlChanged:(UISegmentedControl *)sender { [[NSOperationQueue mainQueue] addOperationWithBlock:^{ [self.tableView reloadData]; }]; }
None of them worked. I also tried scrolling the table view programmatically after rebooting bu, which didn't work either.
Does anyone have any other ideas why this might happen? It should be noted that this problem only occurs on iOS 7.1.
source share