简体   繁体   English

在UINavigationController中关闭视图并同时同步

[英]Dismissing view in UINavigationController and at the same time syncing

There's two views on a NavigationController stack: NavigationController堆栈上有两个视图:

  1. EDIT ITEM-DETAILS VIEW (= basically a form) 编辑项目详细信息视图(基本上是一种表格)
  2. SHOW ALL ITEMS IN A TABLE VIEW 在表格视图中显示所有项目

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导致视图22不是最新的,因为更新发生在后台,并且在完成对表视图数据的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: 在这种情况下:

  • View 2 adds the data to the store. 视图2将数据添加到存储中。 The store notifies that there are changes. 商店通知有更改。
  • View 1 updates on the notification. 查看该通知的1个更新。
  • View 2 also asks the ItemsStore to save the data to the server. 视图2还要求ItemsStore将数据保存到服务器。

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.

相关问题 从UINavigationController视图堆栈中取消显示的UIImagePickerController - Dismissing presented UIImagePickerController from UINavigationController view stack 自动布局-在推送新视图控制器的同时压缩UINavigationController - Autolayout - Compressing UINavigationController at the same time as pushing a new view controller 解散UINavigationController并呈现另一个UINavigationController - Dismissing a UINavigationController and Presenting another UINavigationController iOS消除UINavigationController中的弹出窗口 - iOS Dismissing a popover that is in a UINavigationController 使用UINavigationController关闭UIPopoverController - Dismissing UIPopoverController with UINavigationController 有没有办法在Swift中同时解雇两个uiViewControllers? - is there a way of dismissing two uiViewControllers at the same time in Swift? 将视图推送到不在同一视图层次结构中的UINavigationController - Pushing a view to a UINavigationController that's not in the same view hierarchy 在UINavigationController中为所有视图控制器添加相同的按钮 - Adding same button to all view controllers in UINavigationController UINavigationController,在堆栈上具有相同视图控制器的两个副本 - UINavigationController with two copies of the same view controller on stack 快速关闭视图时,屏幕不时冻结,没有错误 - Screen freezes with no error from time to time when dismissing view in swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM