views:

185

answers:

2

I have View A, when the user clicks a button I pop up View B. When the user dismisses View B, and we return to View A I would like to refresh a label on View A, but is there an event that I can use to detect that we have returned to View B? I know that ViewDidLoad doesn't fire again.

+2  A: 

I'm confused about the views in your question, but you might look into the NSNotificationCenter.

In this case, you would post an NSNotification event when the user dismisses View B.

Views A and B can register with the notification center to listen for this dismissal notification, calling a selector (method) when this notification is heard.

In this method, you might update a label's state or do anything else that involves updating the application state.

Likewise, you might post a notification when View B is popped-up, and have other classes register for that notification type.

More information about NSNotificationCenter is located on Apple's documentation site.

Alex Reynolds
Interesting, thanks! Apologies for the confusion, I'm still getting used to the appropriate lingo.
Driss Zouak
+1  A: 

It sounds like you may be referring to UIViewControllers, rather than UIViews, correct? In that case, you can use -viewWillDisappear: (BOOL) animated and -viewDidDisappear: (BOOL) animated to determine when your viewController is-about-to-be/was-just-dismissed. These should be implemented on View B in your example. If you want to find out when View A is visible again, you can use -viewWillAppear: and -viewDidAppear.

Ben Gottlieb
Yes, UIViewControllers. However I find that the ViewWillAppear and ViewDidAppear does not get fired on View A when View B is dismissed (i.e. this.View.RemoveFromSuperview(); ). I checked this by putting Console.WriteLine statements in my View A for both event handlers, and they only fire the first time that View A appears.
Driss Zouak
That's correct; to get these to fire, you need to be using a UINavigationController (or UITabBarController)
Ben Gottlieb
So then I presume the only way is the NSNotificationCenter. is that correct? Is that going to actually allow View A to update a label on itself after View B has done RemoveFromSuperview? I'm concerned that the way that View A would get notified would be when View A has the label instantiated. An example of this is passing a reference to View B of View A and giving View A a property to access such a label, if View B tries to update it the label is null because View A's label isn't currently instantiated.
Driss Zouak
Additional question, how do you do this with the UINavigationController?
Driss Zouak
figured it out. Cool.
Driss Zouak