刚刚在UITableView类中发现了一个非常奇怪且意外的行为。我需要的最后一个单元格在我的部分是从其他细胞不同的高度,所以我基本上这样做:调用numberOfRowsInSection:from heightForRowAtIndexPath
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == [tableView numberOfRowsInSection:indexPath.section] - 1)
return 44;
else
return 88; //double size for all but the last row
}
似乎很直接,但是当我运行它,我得到无限循环,它崩溃。我确定当我打电话给numberOfRowsInSection:
时,它会调用我的数据源的tableView: numberOfRowsInSection:
方法。这很有意义,因为tableView的方法返回数据源值的高速缓存版本,所以它需要首次从数据源获取值。但是,然后它调用heightForRowAtIndexPath,再次传递indexPath [0,0]!它不停止。
我能够通过使用
[self tableView:tableView numberOfRowsInSection:indexPath.section]
,而不是绕过它(叫我的数据源方法,而不是的tableView的方法)。任何人都知道为什么这样做?这是定义的行为?或Apple的TableView框架中的错误?
看起来像苹果的内部处理。我想我们需要一位苹果工程师来回答这个问题。 – Altealice 2010-12-08 04:02:07
他们不应该漂浮44.0和88.0? – railwayparade 2011-01-11 10:09:43