Part of my AppDelegate code is:
UITabBarController *tabBarController
= (UITabBarController *)self.window.rootViewController;
UINavigationController *navigationController
= [[tabBarController viewControllers] objectAtIndex:0];
PilotosViewController *playersViewController
= [[navigationController viewControllers] objectAtIndex:0];
playersViewController.drivers = players;
But I get this exception:
-[UIViewController viewControllers]: unrecognized selector sent to instance 0x6a75770
***
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController viewControllers]: unrecognized selector sent to instance 0x6a75770'
Where is the mistake?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With