So I've created MainViewController which is a subclass of UITabBarController:
@interface MainV开发者_如何学CiewController: UITabBarController {
}
I initialized this from the app delegate and then set delegate to self:
MainViewController * main = [[MainViewController alloc] init];
main.delegate = self
then I had:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
}
but this was never called.. why is this? Is this because this was a subclass?
Just to clarify: do you have
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
in MainViewController, or in your app delegate?
That method should be defined in whichever class you choose to be your UITabBarControllerDelegate. For example, in my app I have:
- A regular UITabBarController (there's no need to subclass UITabBarController unless you're doing something fancy)
- My app delegate implements UITabBarControllerDelegate - specifically, tabBarController:shouldSelectViewController:
- I set tabBarController.delegate to be the app delegate
That should be everything you need.
精彩评论