【发布时间】:2013-04-22 22:27:03
【问题描述】:
我有 UITableViewController 带有静态分组单元格。在特定视图中,我想删除一些单元格。如果我只是隐藏它们,它会留下一个空白空间,所以我想将单元格的 rowHeight 设置为 0 。我在执行此操作时遇到了麻烦,因为我似乎无法获得要隐藏的单元格的 indexPath。我通过 IB 连接引用了它。阅读后,似乎最好的方法是通过heightForRowAtIndexPath 方法。这是我的代码:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSIndexPath *myIndexPath = [self.tableView indexPathForRowAtPoint:self.billToPostalCell.center];
//crashes here
if ([indexPath isEqual:myIndexPath]) {
return 0;
}
return 44;
}
在此之前,我正在尝试IndexPathForCell,但也会崩溃。根据我的阅读,heightForRowAtIndexPath 应该可以工作,即使单元格不可见。当它崩溃时,调试器中也没有任何显示。
【问题讨论】:
-
你试过注销
myIndexPath返回的行吗?
标签: ios uitableview nsindexpath heightforrowatindexpath