我想添加滑動像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