Search code examples
swiftuitableviewuiviewcontrolleruitabbarcontrollerrefresh

How to proper update table cell info if data was changed in another tab bar controller?


Good day! I really don't know how to ask google for my problem to find good solution. Please help! I have got tab bar controller with T1 and T2 vc. T1 is tableview controller and it shows posts(cells) with like button. So e.g. i look at some post and go to T2 vc. There, i (somehow) navigate to that post and like it. Now if i return back to T1 vc i want that post would be liked. How to do that?

1) I thought about create global array with liked posts and create some update loop in cell to check that array and update data.

2) Or create some delegate methods. But i think it's complex.

If you have some experience in that things, please help. Scheme


Solution

  • Most larger apps will solve this by having at least one service that servers as a single source of truth for some kind of shared data. Each VC then subscribes to this service and updates itself whenever the central store is updated. Examples of this are using CoreData, Realm, or Firebase (all of which allow you to subscribe to changes in a query). If you have a simple app you can implement this yourself by posting your own custom Notification whenever your data changes.