我想实现一个功能,使用Swift 3.0滑动整个表格单元格。就像你可以在iOS 10的邮件应用中滑动删除一样。
重要的是要注意,我不是指滑动来显示一个删除按钮,然后再处理删除。我的意思是用户可以在屏幕上从右向左滑动来删除。(还要注意,tableView是静态的,而不是动态的)
我必须为此实现一个UISwipleGestureRecognizer吗?
发布于 2018-03-09 23:42:31
您可以像实现包含动态内容的表一样实现UITableViewDataSource方法tableView(_:commit:forRowAt:)和tableView(_:canEditRowAt:)。
但是,在包含静态内容的表格中,不能插入或删除行。由于表是静态的,因此应该保留行。您可以做的是更新您的刷行,以反映已删除的状态。
例如:在我的应用程序中,我使用内置的滑动手势来重置设置。用户滑动行(静态内容),点击Delete按钮,应用程序相应地设置该单元格中的标签和图像。该行不会被删除,只是被更新,就像您通常对静态单元格所做的那样(分配出口并像访问其他静态内容一样访问它们)。
编辑:还检查了iOS 11中UISwipeActionsConfiguration类的performsFirstActionWithFullSwipe属性。将其设置为true以允许完整的滑动手势,而不需要安装自己的识别器。
你确实提到了iOS 10邮件;我不知道苹果在iOS 10中是否或如何做到这一点,因为这个属性是iOS 11的一个功能。此外,iOS邮件很可能有一个包含动态内容的表格。
发布于 2017-02-07 06:25:21
您只需添加这些函数并根据需要更改它们即可。
override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
}还有这个
override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
let example1 = UITableViewRowAction(style: .normal, title: "example1") { (action: UITableViewRowAction!, indexPath: IndexPath!) -> Void in
// run your desired action
}
example1.backgroundColor = .white
let example2 = UITableViewRowAction(style: .normal, title: "example2") { (action: UITableViewRowAction!, indexPath: IndexPath!) -> Void in
// run your desired action
}
example2.backgroundColor = .green
let example3 = UITableViewRowAction(style: .normal, title: "example3") { (action: UITableViewRowAction!, indexPath: IndexPath!) -> Void in
// run your desired action
}
example3.backgroundColor = .orange
return [example1, example2, example3]
}https://stackoverflow.com/questions/42077968
复制相似问题