简体   繁体   English

通过设置根视图控制器切换视图有什么问题吗?

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

I was wondering if the following is an accepted way to switch views? 我想知道以下是切换视图的可接受方法吗?

AppDelegate.m 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. 启动应用程序时,将从nib文件中加载viewController和settingsNavigationViewController。

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. 主视图(viewController)包含一个具有3个图像视图的滚动视图,以实现无限滚动效果,并在顶部具有搜索栏,在底部具有工具栏。

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; 这两个视图都有一个调用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 尽管有可能这样做,((Apple文档在此处进行了说明,但似乎并没有阻止这种情况

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIWindow_Class/UIWindowClassReference/UIWindowClassReference.html%23//apple_ref/occ/instp/UIWindow/rootViewController 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];

我认为您必须使用tabbarcontroller。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM