ios - Cell 在 iPad 上没有正确隐藏?

标签 ios iphone objective-c ipad

我想在满足条件时隐藏/删除一行。

我做了一些研究,发现您可以通过为单元格高度返回 0 来做到这一点。

这在 iPhone 上运行良好,但不适用于 iPad。

请指教。

这是问题的截图:

enter image description here

当它没有隐藏时它看起来像这样:

enter image description here

我的代码:

- (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/

相关文章:

iphone - ZipArchive 库编译错误

objective-c - 当应用程序移至垃圾箱或应用程序在 Mac 中被删除时如何收到通知?

Objective-C 从数组中的字符串中删除空格

php - 简单的 JSON php 请求 iPhone

ios - NSArray 元素无法匹配 mapView.annotations 循环中的 Swift 数组元素类型

ios - iTunes Store 不显示应用程序的更新按钮

ios - Xcode 12 和 iOS 15

javascript - iPhone/iPad 上的 session 存储可以持续多长时间?

iphone - 通过自动化脚本在仪器 iOS 标准输出上自定义日志

ios - 如果应用程序第二次运行,从 executeFetchRequest 返回的记录为空