我在导航栏中添加了一个带有IBAction的编辑按钮:
@IBOutlet weak var editButton: UIBarButtonItem!
@IBAction func doEdit(sender: AnyObject) {
if (self.tableView.editing) {
editButton.title = "Edit"
self.tableView.setEditing(false, animated: true)
} else {
editButton.title = "Done"
self.tableView.setEditing(true, animated: true)
}
}
Run Code Online (Sandbox Code Playgroud)
为了去除我有的细胞
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == UITableViewCellEditingStyle.Delete) {
arr.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,这也会激活滑动以删除.如何在不实现swip删除的情况下删除单元格?
解决方案(来自这个答案),翻译成Swift:
override func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
if (self.tableView.editing) {
return UITableViewCellEditingStyle.Delete;
}
return UITableViewCellEditingStyle.None;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12963 次 |
| 最近记录: |