当用户按下主视图控制器上的按钮时,我正在编程地显示模态视图控制器。我拥有的问题是在没有导航栏的情况下显示模态视图。

如何让栏出现?请找到我的代码,让我知道缺少或错误:

-(void)appInfoButtonPressed:(id)sender {
infoViewController *iVC=[[infoViewController alloc] init];
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentViewController:iVC animated:YES completion:nil];
UINavigationController *navBar = [[UINavigationController alloc] initWithRootViewController:iVC];
[self presentViewController:navBar animated:YES completion:nil];
.

}

还在尝试下解散模态视图我有意使用以下行:

[self dismissViewControllerAnimated:YES completion:nil];
.

我应该在主视图控制器的方法中还是在模态视图控制器本身的方法中包含此行?

有帮助吗?

解决方案

删除[自我presentViewController:IVC动画:是完成:nil]; 只是呈现UinaVigationController。

顺便说一下:使用“navbar”命名UinavigationController并不适合。

-(void)appInfoButtonPressed:(id)sender {
    infoViewController *iVC=[[infoViewController alloc] init];
    self.modalPresentationStyle = UIModalPresentationCurrentContext;
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:iVC];
    [self presentViewController:navController animated:YES completion:nil];
}
.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top