Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView scroll content size incorrect after dismissing another view

So I have a UITableViewController which launches another tableVC which changes the number of cells for the original when dismissed.

Upon dismissal, despite returning the correct cell height (and header height) as well as updated number of rows (such that the scroll content is huge), the scroll view only bounces when scrolled. Upon looking at the contentSize property of the scroll of the table, the contentSize is incorrect and is the same as it was previously.

When initially loading the original tableVC, I do not have the problem. If I have a large number of cells, the table will scroll as expected. It is only upon dismissal of the presented tableVC that I run into the problem. One thing I am unsure of is when to call reloadData. I am doing it as follows:

1. in presented tableVC:

[[self presentingViewController] dismissViewControllerAnimated:YES completion:nil]

2. in original tableVC:

-(void)viewDidAppear    
{ 
   //tablecell number manipulated
   [table reloadData];

}

The funny thing is if I rotate to landscape and back to portrait, the contentSize is then set correctly and I can scroll again.

like image 992
Geoff MacDonald Avatar asked Apr 04 '13 13:04

Geoff MacDonald


2 Answers

Add a

[table setNeedsDisplay]; 

Also, is there a particular reason why you are not animating?

like image 184
Mundi Avatar answered Nov 14 '22 01:11

Mundi


I solved this by explicitly reloading the section and not using the reloadData. [table reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];

like image 44
Eduard Mossinkoff Avatar answered Nov 14 '22 02:11

Eduard Mossinkoff