在UINavigationController的驳回视图,并在同一时间同步 [英] Dismissing view in UINavigationController and at the same time syncing

查看:153
本文介绍了在UINavigationController的驳回视图,并在同一时间同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个NavigationController堆栈上两种观点:

There's two views on a NavigationController stack:


  1. 编辑ITEM-详细信息视图(=基本形式)

  2. 显示所有项目在表视图

我不知道是否有对我有任务的最佳实践:

I wonder if there are best practices for the task I have:

当用户点击了UINavigationController的酒吧BACK(而鉴于被 1 )应用程序应该在服务器上更新的项目。

When the user taps "BACK" in the UINavigationController-bar (while being in view 1) the app should update the item on the server.

这不是那么难,但后面行动导致查看 2 2 不起来,到今天为止,因为更新的背景和WASN发生'T通过该表视图的数据GET请求之前完成。

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.

所以为了有看法的 2 始终显示精确的数据,我有几种选择。都有点讨厌。(例如具有视图的ViewController 2 聊到服务器上的 1 的代表以及何时完成,或有一个更新发生的自动更新通知触发重新加载,...)

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?

推荐答案

我想我会做的项目的中心位置。让我们把它叫做ItemsStore。 ItemsStore是有责任有一组最新的项目,并提供访问的项目是独生子。如果新数据到达,或旧的数据被保存它也激发通知。

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.

在这种情况下:


  • 查看2增加的数据存储。该店通知有
    变化。

  • 查看通知1更新。

  • 查看2还询问ItemsStore到
    将数据保存到服务器上。

我不会给装载的责任,并保存到控制器,它会变得丑陋和复杂的。

I would not give the responsibility of loading and saving to the controllers, it will get ugly and complex.

这篇关于在UINavigationController的驳回视图,并在同一时间同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆