Ios 条件导航控制器根

Ios 条件导航控制器根,ios,uinavigationcontroller,Ios,Uinavigationcontroller,我将选项卡栏控制器转换为导航控制器。我想根据用户是否登录来更改导航控制器的根视图。我该怎么做?我不想将代码放入didfishlaunchingwithoptions:或任何其他AppDelegate方法中,因为它不会是用户看到的第一件事 你说得对,应该是: - (void) goNext { NextViewController* nextWindow = [[NextViewController alloc] initWithNibName:@"NextView" bundle:nil]; [

我将选项卡栏控制器转换为导航控制器。我想根据用户是否登录来更改导航控制器的根视图。我该怎么做?我不想将代码放入
didfishlaunchingwithoptions:
或任何其他AppDelegate方法中,因为它不会是用户看到的第一件事

你说得对,应该是:

- (void) goNext {
NextViewController* nextWindow = [[NextViewController alloc] initWithNibName:@"NextView" bundle:nil];
[self.navigationController setViewControllers:[NSArray arrayWithObject:nextWindow] animated:YES];
}
由于无法弹出根视图控制器,因此可以使用以下方法:

- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated
这里有一个链接到
对于这种方法。

你是对的,它应该是:

- (void) goNext {
NextViewController* nextWindow = [[NextViewController alloc] initWithNibName:@"NextView" bundle:nil];
[self.navigationController setViewControllers:[NSArray arrayWithObject:nextWindow] animated:YES];
}
由于无法弹出根视图控制器,因此可以使用以下方法:

- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated
这里有一个链接到
对于此方法。

请参见:[[1]:在第一个答案中,我不知道此数组包含什么。
SetViewController:[NSArray arrayWithObject:detailViewController]
请参见:[[1]:在第一个答案中,我不知道此数组包含什么。
SetViewController:[NSArray arrayWithObject:detailViewController]
因此我在goNext代码中加入了如下内容:
NextViewController*nextWindow=[[NextViewController alloc]init];[self.navigationController setViewControllers:[NSArray arrayWithObject:nextWindow]动画:是]
因为我使用的是故事板而不是NIB,但是当它更改ViewController时,屏幕是黑色的。它没有我放入的按钮或任何其他UI元素。我发现了问题。因为我使用的是故事板,所以这段代码对我有效。
-(void)goNext{UIStoryboard*故事板=[UIStoryboard storyboard with name:@“MainstryBoard”捆绑包:无];NextViewController*nextWindow=[storyboard实例化控件WithiIdentifier:@“NextView”];[self.navigationController SetViewController:[NSArray ArrayWithisObject:nextWindow]动画:是];]
cool,很高兴你能使用它。是的,我应该提到在使用故事板时重新实例化控制器是必要的。所以我在goNext代码中加入了以下内容:
NextViewController*nextWindow=[[NextViewController alloc]init];[self.navigationController setViewControllers:[NSArray arrayWithObject:nextWindow]动画:是]
因为我使用的是故事板而不是NIB,但是当它更改ViewController时,屏幕是黑色的。它没有我放入的按钮或任何其他UI元素。我发现了问题。因为我使用的是故事板,这段代码对我有效。
-(void)goNext{UIStoryboard*故事板=[UIStoryboard storyboard with name:@”MainstryBoard“bundle:nil];NextViewController*nextWindow=[storyboard InstanceeviewController WithiIdentifier:@“NextView”];[self.navigationController SetViewController:[NSArray ArrayWithisObject:nextWindow]动画:是];]
cool,很高兴您能使用它。是的,我应该提到在使用情节提要时重新实例化控制器是必要的。