在 UINavigationController 中关闭视图并同时同步 [英] Dismissing view in UINavigationController and at the same time syncing

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

问题描述

NavigationController 堆栈有两个视图:

There's two views on a NavigationController stack:

  1. 编辑项目-详细信息视图(= 基本上是一个表单)
  2. 在表格视图中显示所有项目

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

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

当用户在 UINavigationController-bar 中点击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.

这并不难,但是 BACK 操作导致查看 2,并且 2 不是最新的,因为更新发生在后台并且没有在对表视图数据的 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 始终显示准确的数据,我有多种选择.有点烦人..(例如让视图 2 的 ViewController 代表 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?

推荐答案

我想我会为 Items 做一个中心位置.让我们称之为 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 个更新.
  • View 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天全站免登陆