这是我在网上获得的代码,它确实适用于我之前开发的项目。但是在这个项目中,当我 NSLog
它时,self.navigationController
为 null ,网上的人讨论过在委托(delegate)文件中添加一些代码,但是我在以前的项目中什么也没发现,我也不太清楚我应该在那里添加什么代码。谁能帮帮我?
UIViewController *next = [[self storyboard] instantiateViewControllerWithIdentifier:@"ViewCollection"];
[self.navigationController pushViewController:next animated:YES];
最佳答案
如果UINavigationController
是nil
,这意味着您使用的 View Controller (从 Storyboard 实例化)实际上并未嵌入 UINavigationController
中。 。
为了将其嵌入 UINavigationController
,您需要拖放 UINavigationController
进入您的 Storyboard,然后按住 Ctrl 键并从 UINavigationController
拖动到您的自定义 View Controller 并将其设置为 rootViewcontroller
的 UINavigationController
.
关于ios - pushViewController 不工作虽然在线阅读很多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30679845/