ich versuche, eine Zelle aus einer TableViewController
zu entfernen. Jedes Mal, wenn ich wische und die Löschtaste drücke, kommt es zu einem Absturz.Wenn ich Zelle aus TableView auf Schaltfläche Aktion entfernen, ist die App abgestürzt - iOS Swift
Dies ist das Crash-Protokoll:
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).'
und das ist meine UITableView
Funktionen.
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)
}
}
was könnte der Grund sein?
Es gibt ein häufiges Missverständnis: 'start/endUpdates' wird für eine einzelne Operation überhaupt nicht benötigt. Es ist nur für mehrere Operationen zum Einfügen/Löschen/Verschieben erforderlich, die sich gegenseitig stören könnten. – vadian
Das Anfangs-/Ende-Update wird nicht nur zum Einfügen/Löschen mehrerer Zeilen/Abschnitte verwendet, sondern es aktualisiert auch die Höhe Ihrer Zeilen, die auf dem Bildschirm angezeigt werden. Ansonsten stimme ich zu, dass es für die Operation für eine Zeile nicht notwendig ist. –