2016-09-28 72 views

回答

4

你应该实现delegate方法 - commitEditingStyle,你会做!

类似,

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

    // below code will delete one row - you can mange another kind of deletion here like delete from database also 
    if editingStyle == .Delete 
    { 
     yourDataArray.removeAtIndex(indexPath.row) 
     self.yourTableView.reloadData() 
    } 
} 

而且你可以在按钮的点击做,

self.yourTableView.setEditing(true, animated: true) 

显示( - )对每一个细胞的标志!

+1

@aldo您可能还有兴趣查看'editActionsForRowAtIndexPath',它可以让您轻扫单元以显示按钮 – GoodSp33d

+0

是啊!提问者也应该查看'editActionsForRowAtIndexPath'! @ GoodSp33d – Lion

+0

@ GoodSp33d我希望单元在点击( - )按钮时自行滑动并显示删除按钮。 –