开发者

Invalidating UITableView contents

开发者 https://www.devze.com 2023-01-02 09:35 出处:网络
I have an application with several UITableViewControllers. Now, the user is allowed to change \"Data source\". In that case I need to invalidate (reset) data in the relevant UITableViews.

I have an application with several UITableViewControllers. Now, the user is allowed to change "Data source". In that case I need to invalidate (reset) data in the relevant UITableViews.

I figured out, that I can use NSNotificationCenter and add these controllers as observers to events which will be generated when the data source changes.

The question is, how do I reset the underlying tables? I can, of course, set some boolean flag, and call UITableView:reloadData in viewWillAppear or viewDidAppear, but I was wondering, if there's a cleaner way of doing it.

Or perhaps I'm completely missing the point, and I don't need NSNotificationCenter altogether开发者_运维知识库. Thank you very much in advance.


The question is, how do I reset the underlying tables? I can, of course, set some boolean flag

I'm not sure why you need to use a flag here. When your view controller gets the notification, have it reload the table in the notification handler.

Updating your table will work a bit differently if your UITableView is attached to an NSFetchedResultsController. Is it?

0

精彩评论

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