2016-01-19 34 views
-1
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { 
if editingStyle == .Delete { 
     // Delete the row from the data source 
    let object: PFObject = self.noteObjects.objectAtIndex(indexPath.row) as! PFObject 
    object.delete() 

When I decided to use delete it worked but the app crashes錯誤迅速當我刪除一行,這樣做,但崩潰

tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) 
} else if editingStyle == .Insert { 
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view 
} 
} 

this is the error * Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.30.14/UITableView.m:1720 2016-01-19 00:07:30.451 Registro1[21154:852511] *

回答

2

從你的代碼看來,你似乎沒有從數據源數組中刪除相應的對象,noteObjects。因此,有數據源陣列數量和之後調用deleteRowsAtIndexPaths

嘗試添加下面一行,TableView中內部計數之間的不匹配調用tableView.deleteRowsAtIndexPaths

self.noteObjects.removeAtIndex(indexPath.row) 
+0

它確實刪除了正確的行 –

+0

現在我有這個錯誤: –

+0

它是一個分段tableview嗎?如果要刪除某一部分中最後一項的行,則需要刪除整個部分。否則,它會拋出這個異常。 –

0

UITableView刪除任何行後,你需要調用reloadData()或者你可以beginUpdatesendUpdates()下扎那方法。

Example:

tableView.beginUpdates() 
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade) 
tableView.endUpdates() 

希望這有助於!

+0

現在我有這個錯誤***斷言失敗之前 - [ UITableView _endCellAnimationsWithContext:],/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.30.14/UITableView.m:1720 2016-01-19 10:21:33.980 Registro1 [21521:899913] *** –

相關問題