2015-02-09 70 views
0

當表被填充我可以改變細胞的顏色與 cell.backgroundColor = UIColor.redColor()在無法變更cell.backgroundColor在Editingstyle.Delete迅速

如果我把它寫在editingstyle .delete它什麼都不做

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 

    let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell") 

    cell.textLabel?.text = toDoListarr[indexPath.row] 

    cell.backgroundColor = UIColor.redColor() 

    return cell 

} 

func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath){ 

    let cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Cell") 

    if editingStyle == UITableViewCellEditingStyle.Delete { 

     NSUserDefaults.standardUserDefaults().setObject(toDoListarr, forKey: "toDoList") 

     cell.backgroundColor = UIColor.yellowColor() 

     toDoList.reloadData() 
    } 

} 

回答

0

您在commitEditingStyle功能嘗試調試,調試是不是在這裏!

請記住,選擇器的commitEditingStyle在協議定義中是@optional,所以你不必實現它。但是,UITableView知道如果你沒有它,爲什麼它應該在代碼中顯示任何可能導致異常的東西。

所以你嘗試改變editActionsForRowAtIndexPath方法中的cell.backgroundColor!

希望它能幫助你。