在swift中向右滑动UITABLEVIEW时添加动作
问题描述:
我有一个常规的uitableview设置,当前用户向左滑动时会出现该动作。我想在用户滑动时添加一个动作,但我无法在Apple文档或网上找到如何执行此操作的任何地方。有什么想法吗?在swift中向右滑动UITABLEVIEW时添加动作
这里是我的当前设置:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
return expandedIndexPaths.contains(indexPath) ? 200.0 : 50.0
}
override func tableView(tableView: UITableView, canMoveRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
// the cells you would like the actions to appear needs to be editable
return true
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
}
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let share = UITableViewRowAction(style: .Normal, title: "Done") { action, index in
let currentElement = self.tipArray[indexPath.row]
let appDel:AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let context: NSManagedObjectContext = appDel.managedObjectContext
var ent = NSEntityDescription.entityForName("Tips", inManagedObjectContext: context)
self.repurposeManagedObjectContext("Tips", forAttribute: "rowNumber", object: indexPath.row)
self.tipArray.insert(currentElement, atIndex: self.tipArray.count)
self.tipArray.removeAtIndex(indexPath.row)
self.tableView.reloadData()
}
// let categorize = UITableViewRowAction(style: UITableViewRowActionStyle, title: <#T##String?#>, handler: <#T##(UITableViewRowAction, NSIndexPath) -> Void#>)
share.backgroundColor = UIColor.blueColor()
return [share]
}