iPhone - UIToolbar - 委托方法/通知/KVC

发布于 2024-10-06 14:14:19 字数 1202 浏览 4 评论 0原文

我正在尝试复制 iPhone 上邮件应用程序的设计。工具栏上的标签更新/更改以显示正在发送的邮件的状态。

复制这个的最好方法是什么?以下是我的想法,也许有人可以提出为什么其中一个可行或一个新想法。

为了统一起见,假设我有以下观点: A -> B-> C-DABC 被推入或推出 UINavigationController,并具有相关的工具栏。 D 是“撰写”窗口,是C 的模式窗口。让我们将我尝试创建的对象称为 obj 。

委托

这需要我在 A 中创建一个 obj 并将其传递给 BC< /代码>。 C 将调用 obj 上的诸如 sendMail 之类的方法,并尝试发送电子邮件。 'obj' 将有一个委托方法 obj:hasUpdateForToolbar: ,它将向委托类 (C) 发送一个数组以更新工具栏。通过发送过程,它将发送多条消息以更新进度条,并在最后说明已成功发送或上次电子邮件检查发生的日期。

此解决方案的问题是它不会更新AB。当 C 被弹出时,委托将需要重新分配给 B,并且在下一个之前,工具栏中会出现(我认为)旧值的闪烁值由 obj 推送。

通知

这比委托更干净,因为您不必将对象传递给每个类,这意味着类之间的依赖性更少)。但由于您没有连接,因此您必须让 C 发布一条通知,告知有一封新邮件可供发送。 obj 必须接收该通知,然后发布新通知而不是委托方法。

问题是,当视图未显示时取消订阅通知是常见的做法。因此,我认为与 B 订阅通知并等待其推送工具栏的下一次更新时会出现相同的闪存。

KVC

我真的不知道如何设置它以便键值编码来处理它。我是否能够在 obj 中设置一个视图,将其放入每个视图的工具栏中,并且当它更新时(使用标签或进度条),它将反映在每个工具栏中?

那么哪个是最好的/我在这些方面缺少什么?

I'm trying to duplicate the design of the mail app on the iPhone. On the toolbar the label updates / changes to show the status of mail being sent.

What is the best way to duplicate this? The following are what I've thought through and maybe someone can suggest why one of them would work or a new idea.

For unity sake, lets say I have the following views: A -> B -> C - D. A, B, and C are pushed on and off the UINavigationController and have the toolbar in question. D is the "compose" window and is a modal window of C. And lets call the object I'm trying to create is obj.

Delegate

This would require me creating one obj in A and pass it to B, and C. C would call a method such as sendMail on obj and it would attempt to send the email. 'obj' would have a delegate method obj:hasUpdateForToolbar: which would send an array to the delegated class (C) in order to update the toolbar. Through the send process it would send multiple messages in order to update a progress bar and at the end to say it was successful sent or a date at which the last email check happened.

The problem with this solution is it doesn't update A or B. When C gets popped off, it the delegate would need to be reassigned to B and there would be (I think) a flash of the old value in the toolbar before the next value is pushed by obj.

Notifications

This would be cleaner than the delegate in that you wouldn't have to pass the object to every class which means less dependency between classes). But since you have no connection you would have to have C post a notification that there is a new mail ready to be sent. obj would have to receive that notification and then would have post new notifications instead of the delegate method.

The problem with this is that it is common practice to unsubscribe to a notification when the view isn't being shown. So I think there would be the same flash as B subscribes to the notification and waits for it to get pushed the next update for the toolbar.

KVC

I'm really not sure how I could set this up so that Key-Value Coding takes care of it. Am I able to setup a view in obj that gets put into the toolbar of each view and as it gets updated (either with a label or progress bar) it would be reflected in every toolbar?

So which is best / what am I missing on these?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木有鱼丸 2024-10-13 14:14:19

您有一个应用程序控制器(可以是您的 AppDelegate 或另一个全局可见的对象。)

该应用程序控制器负责创建模型(获取电子邮件、发送电子邮件等)和 UI(撰写屏幕、UINavigationController、ViewControllers 等)。 )。该应用程序控制器还将负责工具栏的内容:重新加载和撰写按钮以及状态区域。

导航堆栈中的视图控制器不会担心此工具栏的内容,它们只需从应用程序控制器获取工具栏项(撰写、重新加载、状态)。

应用程序控制器将根据其模型的状态(发送、接收等)单独更新工具栏状态区域的内容。应用程序控制器与其模型之间的通信将是典型的 KVO 或通知。

You have an application controller (could be your AppDelegate or another globally-visible object.)

This application controller is responsible creating the models (fetch email, send email etc.) and the UI (the compose screen, the UINavigationController, ViewControllers, etc.). This application controller would also be responsible for the contents of the toolbar: Reload and Compose buttons, and the status area.

The view controllers in the navigation stack wouldn't worry about contents of this toolbar, they would simply acquire the toolbar items (Compose, Reload, Status) from the application controller.

The application controller alone would update the contents of the toolbar status area based on the status of its model (sending, receiving, etc.) Communication between the application controller and its model would then be your typical KVO or notifications.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文