tags:

views:

32

answers:

2

In the below application you can see my current setup where the application launches and depending on whether the user is logged in or not a different uiviewcontroller is added as a subview of the main application [window addSubview:[loggedOutController view]]; My question is within -View1 (Login Screen), once the user attempts to login and it is successful, how can I go back to root level MainApplication and instead of loading the LoggedOut UIVIewcontroller now instead load in the LoggedIn UIViewController? It's unclear to me how to communicate accross.

MainApplication
    - UIViewController (Logged Out)
        -UINavController
            -View1 (Login Screen)
                -View1a (Register Screen)
    - UIViewController (Logged In) 
        -UITabBarController
            -View1 (Settings)
                -UINavController (Handle edit Profile Settings)
                    - View 1
                        -View 1a
                        -View 1b
                        -View 1c
            -View2
A: 

I'm sure there are a multitude of ways to do this. One way to pass information between views is by setting a delegate object. So for instance, create a MainViewController delegate object in LoginScreen, and upon successful login, you can call [delegate onSuccessfulLogin], which will can pop the view stack and run the LoggedIn view controller.

B_
Thanks B_ does that mean I need to set every object below UIViewController as a delegate of the next and implement functions to pass the data back to UIViewController one object at a time or is there a more direct way back to UIViewController without having to touch each object in between?
If your structure needs to pass objects very far back, there are other things you can do. Your main view controller object can be a [singleton](http://en.wikipedia.org/wiki/Singleton_pattern), which basically means you create an instance of the object within its class and function that returns that instance. You can also create a static class where you can set flags for whether you're logged in, etc, and check those flags when appropriate.
B_
A: 

I just found out about NSNotificationCenter seems like this will work, thanks for help!