2017-02-26 58 views
0

我有这样的代码:如何修改行直接的TableView

... 
var items:[String] = [] 

func tableView(tableView: UITableView!, canEditRowAtIndexPath indexPath: NSIndexPath!) -> Bool { 
    return true 
} 
.... 

而且该功能增加更新或删除时,刷卡行:

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { 

    let update = UITableViewRowAction(style: .normal, title: "Update") { action, index in 
     print("Updated") 

     // I NEED THE CODE HERE TO MODIFY THIS ROW 

    } 

    let delete = UITableViewRowAction(style: .default, title: "Delete") { action, index in 
     print("Deleted") 

     self.items.remove(at: indexPath.row) 
     self.tblRefresh.reloadData() 
     UserDefaults.standard.set(self.items, forKey: "items") 
    } 
    return [delete, update] 
} 

我的应用程序是一个To Do列表,并期待这样的:

ToDoList

我需要的代码修改选定行(在此电子邮件xample所选行有“egg”作为值),并在用户按下RETURN时自动保存,无需确认更新。

删除按钮工作正常!

回答

0

修改数据源(self.items),然后致电tableView. reloadRowsAtIndexPaths([indexPath])