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?
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.