Question

I have a UINavigationController and on it I load a rootView that controlls the login process to my application.

I have recently added some code to my application delegate that checks my settings bundle for a logout request when this logout request happens I would like to either reload the rootView so that it loads the login hud, or just call the method inside rootView that shows the login hud.

This is how I set up the rootView for the navigationController inside my appdelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window.rootViewController = self.navigationController; //Adds RootViewController to the NavigationController interface
    // etc
}

What I would like to know is there a way to reload rootViewController? or call a method from it inside the application delegate?

Was it helpful?

Solution

It can be done but it's complicated. Best to avoid it if possible, and the specific requirements will be different for every app. Without seeing the source code for your app we can't tell you how it's done.

The basic process is you need to remove all of them from the view and set all references to nil, and then re-create it either from code or by loading the nib again.

A far better option is to leave the rootViewController where it is, and present a modal login view controller over the top of it. Once the user has logged in, send an NSNotification that the root view controller can observe, and populate its data.

Wait until after the notification has been sent to hide the login controller, and consider having the root view controller block the main thread while it performs any network operations pertaining to logging in. This way the login view (with a "logging in..." message?) will remain visible until the root view is fully populated.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top