Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ios在运行时更改情节提要默认视图控制器_Ios_Uiviewcontroller_Storyboard - Fatal编程技术网

ios在运行时更改情节提要默认视图控制器

ios在运行时更改情节提要默认视图控制器,ios,uiviewcontroller,storyboard,Ios,Uiviewcontroller,Storyboard,是否可以从序列图像板覆盖默认视图控制器以显示不同的控制器?当然,这一切都会发生在AppDelegate中。我肯定会在UINavigationController中嵌入一个rootView,因此您没有两个视图,而是三个视图。一个永远不会发射,只是控制着所有其他的。然后像这样实现其中的方法: - (void) decideViewController { NSString * result; if (myBool) { result = @"yourIdentifi

是否可以从序列图像板覆盖默认视图控制器以显示不同的控制器?当然,这一切都会发生在AppDelegate中。

我肯定会在UINavigationController中嵌入一个rootView,因此您没有两个视图,而是三个视图。一个永远不会发射,只是控制着所有其他的。然后像这样实现其中的方法:

- (void) decideViewController  {
    NSString * result;
    if (myBool) {
        result = @"yourIdentifier";
    }
    else {
        result = @"yourOtherIdentifier";
    }
    self.navigationController.navigationBarHidden = YES; // Assuming you don't want a navigationbar
    UIViewController *screen = [self.storyboard instantiateViewControllerWithIdentifier:@"view1ident"];
    [self.navigationController pushViewController:screen animated:NO]; // so it looks like it's the first view to get loaded
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self decideViewController];
}

看起来第一个视图从未加载过。如果您使用的是NIB,那么您可以从AppDelegate执行所有操作…

@Martol1ni我想使用您的答案,但我也想避免不必要的情节提要混乱,所以我对您的代码进行了一些调整。然而,对于你鼓舞人心的回答,我给了你+1分

我将以下所有内容放在默认控制器上

- (void)gotoScreen:(NSString *)theScreen
{
    AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];

    UIViewController *screen = [self.storyboard instantiateViewControllerWithIdentifier:theScreen];
    [app.window setRootViewController:screen];
}
然后,在逻辑发生的地方,我将根据需要调用以下代码

if(myBool == YES) {
    [self gotoScreen:@"theIdentifier"];
}

默认ViewController在最新SDK的info.pList中声明。它应该在启动时检查一些东西,然后决定推哪个viewcontroller吗?@Martol1ni是的,你说的正是我要找的。你使用的是UINavigationController吗?不,只有
UIViewController
s。我有两个,其中一个是默认值。在
myBool==YES
上,我想用我的第二个控制器而不是默认控制器打开应用程序。