2015-02-09 27 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!

希望它能帮助你。