Question

I was wondering if the following is an accepted way to switch views?

AppDelegate.m

- (IBAction) switchViews
    {
    if (self.window.rootViewController == self.viewController) {
        self.window.rootViewController = self.settingsNavigationViewController;
    } else {
        self.window.rootViewController = self.viewController;
    }
}

Both viewController and settingsNavigationViewController are loaded from nib files when the application launches.

The main view (viewController) contains a scrollview with 3 image views for infinite scrolling effect, as well as a searchbar at the top and a toolbar at the bottom.

The second view is for my application settings. It is a navigation controller that performs similarly to a settings bundle.

Both views have a button that calls switchViews;

Do I need to restructure my app or is this a good way of doing this or do I need to restructure my app?

Was it helpful?

Solution

although its possible to do this, (apples documentation explains here and doesnt seem to prevent this

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html%23//apple_ref/occ/instp/UIWindow/rootViewController

)

it also means your existing views are removed..

It definitely has a bit of a code smell about it. As this is a settings dialog, why not load your settings navigation controller into a modal view as below (in a similar way to the below). Personally this seems a bit cleaner and a bit more consistent with what a user may expect...

[[self.viewController] presentModalViewController:self.settingsNavigationViewController animated:YES];

OTHER TIPS

I think you must use tabbarcontroller.

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