I have a 开发者_Go百科Navigation based application, in which I open a subview for the user to login. Once the user has logged in I'm hiding the view, from inside the subview using
[self.view removeFromSuperview];
However I want to also refresh the data in the RootViewController. From what I understand I need to do the refresh in the viewWillAppear of the RootViewController. How do I call this from inside the subview?
My guess is that its something like this
[rootViewController viewWillAppear];
But obviously rootViewController is not available in the subview.
viewWillAppear
is a method that is called by the controller lifecycle. You should not call it this explicitly, you should override it in your class to perform specific actions regarding you view appearance.
What you should have done, now I am guessing here how your app is based on what you asked, Is to load you login using a modal presentaion, instead of just opening a subview for it.
You could do it using something like this in you controller
LoginController *ctrl = [[LoginController alloc] init];
[self presentModalViewController:ctrl animated: YES];
[ctrl release];
The good thing about doing it is that, after you dismiss you login controller and the rootViewController
is shown again, it will cause your controller viewWillAppear
method to be called again (this time you can refresh your view as desired), and your app will be more like the good practices described in Apple's View Controller Programming Guide for iOS
精彩评论