我想在满足条件时隐藏/删除一行。
我做了一些研究,发现您可以通过为单元格高度返回 0 来做到这一点。
这在 iPhone 上运行良好,但不适用于 iPad。
请指教。
这是问题的截图:
当它没有隐藏时它看起来像这样:
我的代码:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath section]==2 && [indexPath row]==0 && [self hasNoContact]) {
return 0;
}
return 44;
}
hasNoContact
是一个 bool 值,我用它来确定它是否应该被隐藏。
最佳答案
像@Stonz那样做在评论中建议,返回一个空单元格。
it requires me to implement the method and return each possible cell on my tableview. I wish there is an easier way
好吧,你提到它们是静态的,你不必返回每个可能的单元格,你可以从 super
获取它。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([indexPath section]==2 && [indexPath row]==0 && [self hasNoContact]) {
return [[UITableViewCell alloc]init];
}
return [super tableView:tableView cellForRowAtIndexPath:indexPath];
}
关于ios - Cell 在 iPad 上没有正确隐藏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22616071/