【发布时间】:2016-08-08 13:18:17
【问题描述】:
我遇到的问题是,在我删除我的tableview 行后,该行不会被删除,这是代码,我已经按照在线教程,它成功地从数据模型中删除,但它成功了除非我回到前一个屏幕并回到这个视图,否则不要关闭已删除的行,这是为什么呢? :
func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
return true
}
func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if (editingStyle == UITableViewCellEditingStyle.Delete) {
let product = frc.objectAtIndexPath(indexPath) as! Product
let productName = product.name
let message = (MCLocalization.sharedInstance.stringForKey("cart_remove_one_item_message", replacements: ["%s" : productName!]))
let alert = UIAlertController(title: (MCLocalization.sharedInstance.stringForKey("cart_remove_title")), message: message, preferredStyle: UIAlertControllerStyle.Alert)
let OKAction = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: {
(_)in
let managedObject : NSManagedObject = self.frc.objectAtIndexPath(indexPath) as! NSManagedObject
self.moc.deleteObject(managedObject)
self.tableView.reloadData()
do {
try self.moc.save()
} catch {
print("Failed to save.")
return
}
})
alert.addAction(OKAction)
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil))
self.presentViewController(alert, animated: false, completion: nil)
}
}
【问题讨论】:
标签: swift tableview nsfetchedresultscontroller