我有一个UITableview
。除了向左滑动以显示“删除”按钮之外,一切正常。看起来didSelectRowAtIndexPath
是在canEditRowAtIndexPath
之前执行的。如何更改以使其保留并显示删除按钮而不是显示新的 UIView?
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
println("Edit")
return true
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
println("Select")
println(indexPath.row)
let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("CklDtljChnge") as! UIViewController
self.presentViewController(viewController, animated: false, completion: nil)
}
最佳答案
您需要添加这些委托(delegate)方法才能执行此操作。
func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
return UITableViewCellEditingStyle.Delete
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == UITableViewCellEditingStyle.Delete) {
// do your stuff.
}
}
关于ios - didSelectRowAtIndexPath 在 canEditRowAtIndexPath 之前执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32376985/