I know there are many answers of the question in the forum but they didn't help me. Here is my problem.
I have UITableView with UISegmentedControl. In the one segment there is less data than in the other one. After rotation or segment switch, I invoke reloadData to ensure that the entire data is displayed. That works.
Now, the user clicks on a cell and goes to another view using the same UISegmentedControl. It is intended that the same control is used, I want that both views show the same perspective to the data. The problem appears when the user sees the perspective with less data on the first screen, goes to the second and changes the perspective to the data there. Then he goes back and is not able to scroll to the bottom of the table. If he rotates the screen or changes the segment, everything is fine again.
I tried solving the problem by implementing viewWillAppear: and reducing/calculating there the height of the tableView. Unfortunately, it didn't worked. Invoking reloadData doesn't help neither. Actually, the tableView is already reloaded when switching the segment... But still, I am not able to see the last cells of the table.
Any ideas?
EDIT:
Here are the heights that I get from the tests (without resizing):
NSLog(@"Before switch: %f, %f", self.tableView.frame.size.height, self.tableView.contentSize.height); --> Before switch: 372.000000, 471.000000
NSLog(@"After switch: %f, %f", self.tableView.frame.size.height, self.tableView.contentSize.height); --> After switch: 372.000000, 585.000000
The tableView remains the same, only the contentSize increases. I tried setting the value of the one to the value of the other, reducing the values etc. but I don't really know what should be done...
EDIT2:
All contentSize and height values seem to be fine. However, I realized that the problem is somehow related to the custom header view on the screen. When I remove it from the table view, it scrolls to the end. With the header view, however, it does not. I don't change anything from the header view, it is just a view with buttons on the top of the table.
It because your tableView's frame height is exceeding the visible area. Decrease the tableView's frame height to be inside the visible area. You will see everything.
tableView.contentSize = CGSizeMake(widthYouWant, heightYouWant);
After some hours of experiments, I increased the contentSize.height property of the tableView by one and now everything works fine. I have no idea why that works but it is a solution. By the way, decreasing the property by one leads to the same result. In both cases, the table is correctly displayed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With