您好我想在发生错误后删除tableview单元
由于未捕获的异常终止应用' NSInternalInconsistencyException',原因:'无效更新:无效的节数。更新后的表视图中包含的节数(4)必须等于更新前的表视图中包含的节数(5),加上或减去插入或删除的节数(0插入,0删除)
这是代码
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return sectionTitle.count
}
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let sTitle = sectionTitle[section] as? String
let sectionAnimals = dict.objectForKey(sTitle!) as! NSArray
print(sectionAnimals)
return sectionAnimals.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let sTitle = sectionTitle.objectAtIndex(indexPath.section) as! NSString
let sectionAnimals = dict.objectForKey(sTitle)
let animal = sectionAnimals!.objectAtIndex(indexPath.row) as! NSString
cell.video_name.text = animal as String
let sectionAnimals1 = dict1.objectForKey(sTitle)
let animal1 = sectionAnimals1!.objectAtIndex(indexPath.row) as! NSString
cell.artist_name.text = animal1 as String
}
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! DetailTableViewCell
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let deleteAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete") { (action, indexPath) -> Void in
tableView.beginUpdates()
self.dict.removeObjectForKey(self.sectionTitle[indexPath.section])
self.dict1.removeObjectForKey(self.sectionTitle[indexPath.section])
self.dict2.removeObjectForKey(self.sectionTitle[indexPath.section])
let newArr = NSMutableArray(array: self.sectionTitle)
newArr.removeObjectAtIndex(indexPath.section)
self.sectionTitle = newArr
tableView.reloadData()
tableView.endUpdates()
}
}