开发者

How to call viewWillAppear from a subView

开发者 https://www.devze.com 2023-03-05 07:44 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消