[英]Dismissing view in UINavigationController and at the same time syncing
There's two views on a NavigationController stack: NavigationController堆栈上有两个视图:
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. 当用户在UINavigationController栏中点击“返回”时(在视图1中 ),应用程序应更新服务器上的项目。
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. 并不是那么困难,但是BACK-action导致视图2和2不是最新的,因为更新发生在后台,并且在完成对表视图数据的GET请求之前还没有通过。
So in order to have view 2 always show accurate data, I have several options. 因此,为了使视图2始终显示准确的数据,我有几种选择。 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, ...)
有点烦人..(例如,让视图2的 ViewController代表1与服务器通信并在完成时进行更新,或者让“更新发生”通知触发重新加载,...)
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。 ItemsStore is a singleton that has the responsibility to have a set of the latest items and give access to the items.
ItemsStore是一个单例,它负责获取一组最新商品并提供对这些商品的访问权限。 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. 我不会将加载和保存的责任交给控制器,这将变得很丑陋和复杂。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.