ios - 如何在 Swift 中隐藏/删除空 TableView 行?

标签 ios swift xcode uitableview tableview

您好,我有 TableView 从 API 获取数据

但我想显示具有特殊条件的行

我试图隐藏我不想要的行,但我不想在单元格中显示它们

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell: DetailsListCell = tableView.dequeueReusableCell(at: indexPath)
    switch self.type!{
    case "inbox":
        if inboxData[indexPath.row].delYn != "Y"{
           cell.configure(withDate: inboxData[indexPath.row].dodate, withName: inboxData[indexPath.row].deptNm, withMsgNameBottom: inboxData[indexPath.row].title)
        }else{
            cell.isHidden = true
        } 

最佳答案

您不应该在此方法中隐藏单元格。相反,您应该有一个数据模型或一些指示器,它应该告诉 TableView 要显示哪些行以及要隐藏哪些行。

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 3 // only the number of rows to show
}

关于ios - 如何在 Swift 中隐藏/删除空 TableView 行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58819579/

相关文章:

ios - Checkmark 在所有 23 个国家/地区的同一地点均被接受。但是我怎样才能将它设置为一个地方

ios - 添加 cocoapods 后在 Xcode 中导致错误的框架

ios - UIWebView 包装器与 native 组件

ios - 在 Realm 之间复制对象时需要迁移

iphone - 加载新 View

ios - 如何定义 Siri 意图参数关键字的同义词?

ios - 错误 ITMS-90642 : "Missing Info.plist Key. Your app' s info. plist 必须包含 'MSMessagesExtensionStoreIconName' key 。”

swift - 无论如何只能访问 child 字典的值(value)?

iphone - 我可以在 Interface Builder 中重复使用颜色吗?

ios - 在 iOS 中,即使设备处于同一个位置,也会检测到不同的位置