2015-11-15 30 views
0

我想創建一個使用swift2的todolist。首先我創建了一個表,並且該表中的每一行實際上都是存儲具有兩個屬性(稱爲「title」和「description」)的結構的數組的元素,當我嘗試向我的表添加新任務時它工作正常當我想刪除它,我把它拖到一邊工作正常,但沒有紅色刪除標誌出現,所以我不能真正刪除它,當我點擊其他地方 - 行 - 將回到它在這裏的地方是我的代碼爲刪除部分單元格刪除的UITableView和紅色標誌

func tableView (tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { 
     if (editingStyle == UITableViewCellEditingStyle.Delete){ 
      mgr.tasksArray.removeAtIndex(indexPath.row) 
      TableTask.reloadData() 
     } 
    } 

謝謝:)

+1

你好,歡迎來到StackOverflow。請花一些時間閱讀幫助頁面,尤其是名爲[「我可以詢問什麼主題?」(http://stackoverflow.com/help/on-topic)和[「我應該問什麼類型的問題避免問?「](http://stackoverflow.com/help/dont-ask)。更重要的是,請閱讀[Stack Overflow問題清單](http://meta.stackexchange.com/q/156810/204922)。您可能還想了解[最小化,完整和可驗證示例](http://stackoverflow.com/help/mcve) – mnencia

回答

0

下面的代碼比較你:

class TableViewController: UITableViewController { 
    var content = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"] 

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) 
    cell.textLabel?.text = content[indexPath.row] 
    return cell 
    } 

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return content.count 
    } 

    override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { 
    if editingStyle == .Delete { 
     self.content.removeAtIndex(indexPath.row) 
     tableView.reloadData() 
//  tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic) -> the better option in my opinion 
    } 
    } 
} 
+0

再次交換,但不顯示刪除符號 –

0

對於那些後來提到這個問題的人來說,我的錯誤是我沒有指定所需的約束,因此表的某些部分只是在屏幕之外。 我希望它能幫助你:)

相關問題