当我每次向左滑动以删除我的应用程序崩溃时运行我的应用程序,它指向线程1:信号SIGABRT
“我相信这是我的代码的一部分导致它。
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
allItems[indexPath.section].removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
} else if editingStyle == .Insert {
let newData = DataItem(title: "New Data", subtitle: "", imageName: nil)
allItems[indexPath.section].append(newData)
tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
}
}
override func setEditing(editing: Bool, animated: Bool) {
super.setEditing(editing, animated: animated)
if editing {
tableView.beginUpdates()
for (index, sectionItems) in allItems.enumerate() {
let indexPath = NSIndexPath(forRow: sectionItems.count, inSection: index)
tableView.insertRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
}
//tableView.beginUpdates()
tableView.setEditing(true, animated: true)
tableView.endUpdates()
} else {
tableView.beginUpdates()
}
您可以像这样修改代码:
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
allItems[indexPath.section].removeAtIndex(indexPath.row)
tableView.reloadData()
} else if editingStyle == .Insert {
let newData = DataItem(title: "New Data", subtitle: "", imageName: nil)
allItems[indexPath.section].append(newData)
tableView.reloadData()
}
}