im trying to remove a cell from a TableViewController
. Each time i swipe and press the delete button a crash occur.
This is the crash log:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (10) must be equal to the number of rows contained in that section before the update (10), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'
and this is my UITableView
functions.
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let myCell = tableView.dequeueReusableCellWithIdentifier(cellID, forIndexPath: indexPath) as! PredefinedServicesCell
//Cell configuration.
myCell.selectionStyle = .None
myCell.containerView.layer.borderColor = UIColor(hex: 0x3399CC).CGColor
myCell.containerView.layer.borderWidth = 1
myCell.containerView.layer.cornerRadius = 10
myCell.containerView.clipsToBounds = true
myCell.servicePrice.text = "\(indexPath.row)"
myCell.serviceCurrency.text = "KWD"
myCell.serviceTitle.text = "Building iOS Application"
myCell.serviceDescription.text = "This is a service description This is a service description This is a service description This is a service description This is a service description This is a service description This is a service description This is a service description This is a service description"
return myCell
}
override func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
}
}
what might the reason be?