2016-09-28 152 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我希望單元在點擊( - )按鈕時自行滑動並顯示刪除按鈕。 –