2016-05-18 56 views
0

我有一個常規的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] 
} 

回答