“Unrecognized selector sent to instance” error

前端 未结 3 978
走了就别回头了
走了就别回头了 2021-01-14 07:09

Part of my AppDelegate code is:

UITabBarController *tabBarController 
    = (UITabBarController *)self.window.rootViewController;

UINavigationController *na         


        
相关标签:
3条回答
  • 2021-01-14 07:32

    I met the same issue, because I followed the steps by the author, but

    UINavigationController *navigationController 
        = [[tabBarController viewControllers] objectAtIndex:0];
    

    this is what which made the crash, because navigationController is not at index=0, I did exchange the locations of the two tab bar items, then it works.

    0 讨论(0)
  • 2021-01-14 07:38

    You need to make sure that you connect things properly in your XIB or storyboard. The exception is showing you that the object is of type ViewController when you send [tabBarController viewControllers] and you were expecting a UITabBarController. That's why you're getting '-[ViewController viewControllers]:. Make sure that your root view controller really is a tab view controller.

    0 讨论(0)
  • 2021-01-14 07:46

    You are obviously receiving different type of object on index = 0.

    If you are using storyboard go there and open Navigator > find specific controller > see Relationships. This order can be used when referencing its viewControllers collection.

    0 讨论(0)
提交回复
热议问题