从 UINavigationController 启动一个新的 UIViewController
Start a new UIViewController from a UINavigationController
我有一个 UINavigationController
,我想从那个导航开始一个新的 UIViewController
,它有自己的视图控制器。
当我尝试这样做时,我遇到了这个异常
Could not load NIB in bundle loaded)' with name and directory 'Main.storyboardc''
我正在用这两行代码添加新的视图控制器
UIViewController *mainViewController =[self.storyboard instantiateViewControllerWithIdentifier:@"CGMainViewController"];
[self presentViewController:mainViewController animated:NO completion:nil];
有没有什么方法可以从导航控制器启动一个新的 UIViewController
而无需将其添加到该导航中?
您可以:
[self presentViewController:newViewController animated:YES completion:nil];
模态呈现一个新的UIViewController
而不将其添加到UINavigationController
堆栈
此外,如果您希望新 VC 位于新 UINavigationController
中,则:
UINavigationController * nc = [[UINavigationController alloc] initWithRootViewController:newViewController];
[self presentViewController:nc animated:YES completion:nil];
如果您的问题更清楚,我可以提供更多信息,并提供一些导致错误的代码。
Solved
我的代码 运行 正确
The exception
appears because of a typing mistake of the identifier for the new view controller in the storyboard
我有一个 UINavigationController
,我想从那个导航开始一个新的 UIViewController
,它有自己的视图控制器。
当我尝试这样做时,我遇到了这个异常
Could not load NIB in bundle loaded)' with name and directory 'Main.storyboardc''
我正在用这两行代码添加新的视图控制器
UIViewController *mainViewController =[self.storyboard instantiateViewControllerWithIdentifier:@"CGMainViewController"];
[self presentViewController:mainViewController animated:NO completion:nil];
有没有什么方法可以从导航控制器启动一个新的 UIViewController
而无需将其添加到该导航中?
您可以:
[self presentViewController:newViewController animated:YES completion:nil];
模态呈现一个新的UIViewController
而不将其添加到UINavigationController
堆栈
此外,如果您希望新 VC 位于新 UINavigationController
中,则:
UINavigationController * nc = [[UINavigationController alloc] initWithRootViewController:newViewController];
[self presentViewController:nc animated:YES completion:nil];
如果您的问题更清楚,我可以提供更多信息,并提供一些导致错误的代码。
Solved
我的代码 运行 正确
The
exception
appears because of a typing mistake of the identifier for the new view controller in thestoryboard