开发者

Resizing UITableView frame based on data

From an earlier post UITableView, only showing UITableViewCells with data, I was able to resize my UITableView accordingly. I do this resizing in the method:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

I declare a CGRect originalFrame to hold my original tableView size because I was getting a problem where if I went from smaller to larger rows (i.e. 1 to 5 rows), the 5 rows would then show in 1 row space only instead of the 5. So in my viewDidLoad method, I reset the tableView.frame to the originalFrame. It pretty much works. However, the nuance I see now is, it still remembers the last selection when loading the table, then when you开发者_如何学Python touch the table, it reloads correctly. For example, let's say I am showing 3 rows of data, then I move to a selection that has 5 rows of data. When the UITableView reloads, it first only shows 3 rows worth of data, then when I touch the UITableView, the next two rows magically appear, and it works like normal. It only happens if I go from smaller to larger. If I start out at a selection that has 5 rows of data, it looks fine. Then I go to a smaller selection that has 3 rows of data, then it automatically resizes to 3 rows. Any thoughts? Am I not redrawing at the right time? Am I putting my resizing in the right place?


Try this:

[myTableView reloadData];

after you adjust the frame.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜