3

I'm facing a strange error in my iOS app and haven't been able to figure out the reason why.

In my UITableView i can add new cells, so i refresh the array that is the datasource and call reloadData.

Everything works without error. The numberOfRowsInSection is called again, and it's value is one more than it's previous value was. The new cell even gets inserted at the bottom of the tableview, but i cant scroll down to it. I only know that it's there because the tableview bounces and i can see it.

I'm guessing the tableview's content height is not getting increased for some reason, but i have no idea why.

I'm using iOS 6 btw.

Any help is very much appreciated! Thanks,

Zoli

EDIT, answers for Srikanth's questions:

  1. How is data getting added.

There's an NSArray containing objects of a specific type. The array.count is the number of the number of cells. This NSArray gets its values from a database query.

  1. When you say, you are refreshing the array, what do you mean.

By refreshing the array i mean i execute a new query in the database and put the results of this query into an NSArray. this will be the tableview's datasource array. Like this:

dataSourceArray = [dbManager executeQuery];
[tableView reloadData];
  1. Are you adding the data within the same view controller

Yes.

  1. Can you show some code as to what you are doing

See above.

  1. Is the table view at the root of the view controllers view or is it within another view

The tableview is the main view's first child.

  1. Can you try adding data to the array at the beginning, so that you can view the cell being added at the top.

I don't understand what you mean.

4

3 回答 3

0

我遇到了同样的问题,我能够让它表现正确的唯一方法是不使用 reloadData,而是重新加载所有部分(归结为同一件事,但显然不是在内部 UITableView contentSize 重新计算)。

无论如何,当你的模型被加载时,不要做 [ self.myTableView reloadData ],而是调用这个:

-(void)reloadDataWithAnimation {
    [self.myTableView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.myTableView.numberOfSections)] withRowAnimation:UITableViewRowAnimationTop];
}

动画不是必需的,我只需要它看起来那样。

于 2013-11-21T09:17:17.807 回答
0

检查您的 tableView:heightForRowAtIndexPath: 方法。对于新添加的行,此方法可能会以某种方式返回零。

于 2012-12-12T09:27:09.447 回答
0

答案是确保在调用 tableview 的 reloaddata 之前从数据库中获取新内容。由于某种原因,新内容在 tableview 中,但其内容高度较小。我的猜测是 numberOfRowsInSection 在新结果进入数组之前被调用,但它的内容来自带有新数据的数组。但这也没有意义……

但是确保只有在获取查询完成后才重新加载 tableview 的回调解决了问题。

于 2012-12-12T17:02:05.443 回答