Reputation: 265
I want delete cell from tableViewController, But the problem is deleting the next cell Example : array : [1,2,3,4,5] when i'm delete 2 from table, automatically the code deleting 3 from DataBase
here is my code :
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
array_prodacts.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
let currentCell = tableView.cellForRowAtIndexPath(indexPath) as! TableViewCell2 }}
Upvotes: 0
Views: 58
Reputation: 5426
The problem is here array_prodacts.removeAtIndex(indexPath.row)
because the tableview
is zero based index so indexPath
of the element 1 in your array is 0, 2 is 1, 3 is 2, 4 is 3 and 5 is 4. So deleting the index 2 reflects the deleting of the value 3 (has index 2) in your array
Upvotes: 1