开发者

How to refresh uitableview/nsmutablearray after adding object to underlying nsmanagedobjectcontext

开发者 https://www.devze.com 2023-02-12 22:38 出处:网络
I have a basic UITableViewController that displays a list of schools, fetched from a simple two-entity core data repository.The tableview is bound to an NSMutableArray of schools that is loaded from a

I have a basic UITableViewController that displays a list of schools, fetched from a simple two-entity core data repository. The tableview is bound to an NSMutableArray of schools that is loaded from an NSManagedObjectContext.

I added a "add new school" button which presents the user with a form for adding a new school. When the user adds the new school and clicks "save", I save the new school object to the NSManagedObjectContext and pop the "add school" view from the navigation stack. I am sent back to the original uitableview and 开发者_StackOverflow社区the new school IS NOT in the list.

I know that I need to refresh the tableview, upon return, but am unsure how. NOTE: if I exit the simulator and run the program again, the new school record appears, so I know it is getting added properly to the underlying store.

Pretty sure I need to implement an NSFetchedResultsController but that seems like a TON OF CODE for what seems to be something quite straightforward.

If NSFetchedResultsController is the only way, can someone direct me to a tutorial or a code listing that may show this flow?

Many thanks.

Phil


Try reloading the data in your viewWillAppear method:

- (void)viewWillAppear:(BOOL)animated {
    [self.tableView reloadData]
}

PS: I'd still recommend you look in to using a fetched results controller. A lot of the code is boiler plate and you won't normally need to touch it.

0

精彩评论

暂无评论...
验证码 换一张
取 消