I have a uitabbarcontroller, which contains multiple tabs and viewControllers.
I am trying to loop through the view controllers to find the right one and call a method.
but the type of the view controller i get, each time i go through the loop is a UINavigationController. So how can i simply access a view controller in my tabBar?
for (UIViewController *v in self.tabBar.viewControllers)
{
if ([v isKindOfClass:[MyViewController class]])
{
MyViewController *myViewController = v;
[v doSomething];
}
}
You most likely have UINavigationControllers at the root of your Tabs, so what you will want to do is access the ViewController displayed by the UINavigationController.
Try changing the code to the following: