作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
这是连接到我的 TableView 的所有功能。为什么我不能删除行?
我也在 viewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
self.myTableView.dataSource = self
self.myTableView.delegate = self
self.myTableView.reloadData()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arr.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: UITableViewCellStyle.subtitle, reuseIdentifier: "incTV")
cell.textLabel?.text = "X"
cell.detailTextLabel?.text = "Y"
return cell
}
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
if editingStyle == .delete {
myTableView.deleteRows(at: [indexPath], with: .fade)
arr.remove(at: (indexPath as NSIndexPath).row)
self.myTableView.reloadData()
}
}
override func viewWillAppear(_ animated: Bool) {
myTableView.reloadData()
}
最佳答案
首先确保你的表有一个委托(delegate)集,并且你的委托(delegate)方法在委托(delegate)类/ Controller 中。
其次,尝试使用 canEditRowAtIndexPath
方法并返回 true。
关于ios - 如何在 Swift 3 的 editingStyle 中识别 .delete 以删除 tableview 中的单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39936570/
我是一名优秀的程序员,十分优秀!