【问题标题】:Delete UITableViewCell that has IBOutlets in it删除其中包含 IBOutlets 的 UITableViewCell
【发布时间】:2017-08-28 07:14:26
【问题描述】:

应该很简单,但我忘了。我是否需要在 delete 方法以及 cellForRowAt 中将单元格出列?

这是细胞:

class Row : UITableViewCell {
@IBOutlet weak var name: UILabel!
@IBOutlet weak var rating: UILabel!
@IBOutlet weak var address: UILabel!
@IBOutlet weak var status: UILabel!

}

删除方法如下:

 override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
    print(indexPath.row)

    if (editingStyle == .delete) {

        tableView.deleteRows(at: [indexPath], with: .automatic)
    }
}

如何添加要删除的变量?我知道我不能简单输入例如:

name.remove(at: indexPath ) <-- or something like that. whats the cleanest method? Thanks 

【问题讨论】:

  • Stream 你能解释一下你的问题吗?这里叫什么名字?
  • 你必须先从dataSource数组中移除对象,然后使用deleteRows

标签: ios uitableview swift3 xcode8


【解决方案1】:

如果您的意思是获取您删除的行。

let cell = tableView.cellForRow(at: IndexPath)

在您删除该行之前在使用这个。

并且您必须在删除行之前从数据源中删除数据。在这种情况下,您需要dataArray.remove(at: indexPath.row)

【讨论】:

  • 如果 IBOutlets 连接到 CoreData...我可以只删除数据而不是删除每个变量,对吗?像上面一样。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-10-12
  • 1970-01-01
  • 2016-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-29
相关资源
最近更新 更多