Refresh NSFetchedResultsController data?

前端 未结 4 748
暗喜
暗喜 2021-02-07 11:48

I can create new managed objects inside my app, in a separate view I have a table view which shows all the objects I have.

When I create a new managed object (in a total

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-07 12:38

    You are setting your UITableViewController as the NSFetchedResultsControllerDelegate. That's good. Now try to implement the controllerDidChangeContent: method in the TableViewController like so:

    - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller {
       [self.tableView reloadData];
    }
    

    Your NSFetchedResultsController will listen to removed or new objects in Core Data and notify its delegate (your TableViewController) of changes. Check the Core Data template project in Xcode to implement this even better with add and removal animations in the UITableView.

提交回复
热议问题