There's two views on a NavigationController stack:
I wonder if there are best practices for the task I have:
When the user taps "BACK" in the UINavigationController-bar (while being in view 1 ) the app should update the item on the server.
That's not so difficult, but the BACK-action leads to view 2 , and 2 is not up-to date, because the update happened in the background and wasn't through before the GET-request for the table view data finished.
So in order to have view 2 always show accurate data, I have several options. All a bit annoying.. (for example having ViewController of view 2 talk to server on 1 's behalf and update itself when completed, or having a "update happened" notification that triggers a reload, ...)
But.. what's a good best-practice for this case?
I think I would make a central place for the Items. Lets call it a ItemsStore. ItemsStore is a singleton that has the responsibility to have a set of the latest items and give access to the items. It also fires notifications if new data arrives, or old data is saved.
In this case:
I would not give the responsibility of loading and saving to the controllers, it will get ugly and complex.
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.