在Swift 2.0中转换后我无法解决问题:
“Objective-C方法 '控制器:didChangeObject:atIndexPath:forChangeType:newIndexPath:' 方法提供 '控制器(:didChangeObject:atIndexPath:forChangeType:newIndexPath :)' 与可选的需求方法冲突 '控制器(:didChangeObject:atIndexPath:forChangeType:newIndexPath :)' 在协议'NSFetchedResultsControllerDelegate'“
请帮帮我。 并感谢提前
func controllerWillChangeContent(controller: NSFetchedResultsController) {
tableView.beginUpdates()
}
func controller(controller: NSFetchedResultsController, didChangeObject anObject: NSManagedObject, atIndexPath indexPath: NSIndexPath?, forChangeType type: NSFetchedResultsChangeType, newIndexPath: NSIndexPath?) {
// the issue is here
switch type {
case NSFetchedResultsChangeType.Insert:
if let newIndex = newIndexPath {
tableView.insertRowsAtIndexPaths([newIndex], withRowAnimation: UITableViewRowAnimation.Automatic)
}
case NSFetchedResultsChangeType.Delete:
if let index = indexPath {
tableView.deleteRowsAtIndexPaths([index], withRowAnimation: UITableViewRowAnimation.Automatic)
}
}
}
func controllerDidChangeContent(controller: NSFetchedResultsController) {
tableView.endUpdates()
}
答案 0 :(得分:5)
更改 public bool Delete<E>(E entity) where E : class
{
DataContext.Entry(entity).State = System.Data.EntityState.Deleted;
DataContext.SaveChanges()
}
的来电didChangeObject anObject: NSManagedObject
。新方法如下所示:
didChangeObject anObject: AnyObject