开发者

Is there anything wrong with switching views by setting the root view controller?

开发者 https://www.devze.com 2023-03-05 21:42 出处:网络
I was wondering if the following is an accepted way to switch views? AppDelegate.m - (IBAction) switchViews

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 settin开发者_JAVA百科gs. 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?


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];


I think you must use tabbarcontroller.

0

精彩评论

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

关注公众号