Confusion about initWithNavigationBarClass - how to use (new instanceType method)

独自空忆成欢 提交于 2019-12-01 17:59:40
self.window.rootViewController.viewControllers = @[firstPage];

does not compile because the rootViewController property of UIWindow is declared as a (generic) UIViewController (which does not have a viewControllers property), and not as a UINavigationController.

The compiler does not "know" that the root view controller is actually a navigation controller in your case.

So either you proceed as in your first code block, or you have to add an explicit cast:

((UINavigationController *)self.window.rootViewController).viewControllers = @[firstPage];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!