I created a simple Tab Bar app via the template in XCode 4.5.1 which gave me two view controllers like this in the app_delegate:
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = @[viewController1, viewController2];
self.window.rootViewController = self.tabBarController;
In viewController1, I have an instance method that writes out some login / logout buttons. One of the callbacks is in app_delegate and would like to call the instance method in viewController1. I tried this:
[[self.tabBarController.viewControllers objectAtIndex:0 ] renderButton];
but it’s not working. Is this type of query possible or should I use some other technique?
thx in advance
What you’ve written should work. A cast isn’t necessary (though it does make the code more readable). If you are certain
renderButtonisn’t being called (put a breakpoint or NSLog message in this method), my guess is that you forgot to declare it in the FirstViewController’s header file.