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

前端 未结 1 1504
感情败类
感情败类 2021-01-19 02:41

This works great:

UINavigationController *nc =
    [[UINavigationController alloc]
    initWithNavigationBarClass:[GTScrollNavigationBar class]
    toolbarCl         


        
相关标签:
1条回答
  • 2021-01-19 03:18
    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];
    
    0 讨论(0)
提交回复
热议问题