简体   繁体   中英

Updating item in CoreData doesn't refresh tableView

I have a little problem and tried everything to figure it out. I know the problem but I don't know how to solve it. I'm using CoreData with a fetchedResultsController. My entity is called "name" and the SortDescriptor is also for "name". If I have one single Item saved to CoreData and change the name value, FetchedResultsController calls .move instead of .update and the label in my TableView doesn't get updated. After restarting the Application or changing a different value of the Item, name is also updated. If I have more than one Item saved to CoreData everything works without any problems.

How to keep the SortDescriptor on "name" but also update the value in my tableView.

Thanks

The easiest solution is to subscribe to name property of our data item via KVO. Just add your cell as observer and update your UI elements as soon as your data object is changed.

NB. Don't forget to unsubscribe in prepareForReuse

不要忘记将: self.tableView.reloadData()放在正确的位置。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM