开发者

didSelectViewController for subclass of UITabBarController not working

开发者 https://www.devze.com 2023-04-07 00:46 出处:网络
So I\'ve created MainViewController which is a subclass of UITabBarController: @interface MainV开发者_如何学CiewController: UITabBarController {

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号