我想添加滑动像this,实际上这个库是Android的。我想迅速。刷卡撤消像gmail的撤消
我已经使用默认的tableview方法。
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]?
但问题是它只提供了一种方法,不是左右滑动。
也在GMAIL应用程序有两端刷卡,甚至我们我们刷两次,该行将被自动删除。
请指导我如何做到这一点。我无法找到任何第三方。
有一件事我已经创建添加左侧和右侧手势,然后在他们的方法中添加按钮,但没有发生。
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let moreRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "More", handler:{
action, indexpath in
print("MORE ACTION");
self.Selected = "YES"
self.selectedValue = indexpath.row
self.tableView.rowHeight = 50
self.tableView.beginUpdates()
let indexPath = NSIndexPath(forRow: indexPath.row, inSection: 0)
self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
self.tableView.endUpdates()
});
moreRowAction.backgroundColor = UIColor(red: 0.298, green: 0.851, blue: 0.3922, alpha: 1.0);
let deleteRowAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete", handler:{action, indexpath in
print("DELETE ACTION");
self.tableView.endUpdates()
});
let Action = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "", handler:{action, indexpath in
print("ACTION");
});
if self.Selected == "YES" {
if self.selectedValue == indexPath.row {
return [Action];
}
//return [Action];
return [deleteRowAction, moreRowAction];
}else{
return [deleteRowAction, moreRowAction];
}
}
并且允许编辑
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return false
}
用于手势
self.tableView.registerNib(UINib(nibName: "customCell", bundle: nil), forCellReuseIdentifier: "customCell")
let swipeRight = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.left(_:)))
swipeRight.direction = UISwipeGestureRecognizerDirection.Right
self.tableView.addGestureRecognizer(swipeRight)
let swipeleft = UISwipeGestureRecognizer(target: self, action: #selector(ViewController.right(_:)))
swipeleft.direction = UISwipeGestureRecognizerDirection.Left
self.tableView.addGestureRecognizer(swipeleft)
func left(sender: UISwipeGestureRecognizer){
print("left");
//what to write inside to make custom button here
}
func right(sender: UISwipeGestureRecognizer){
print("right");
}
你为什么不添加自定义单元格里面两种意见(内容,行动)在你刷卡之间切换 – zombie