0

头文件:

#import <UIKit/UIKit.h>

@interface PFXTabControllerViewController : UITabBarController <UITabBarControllerDelegate>
@end

实现文件:

#import "PFXTabControllerViewController.h"

@interface PFXTabControllerViewController ()
@end

@implementation PFXTabControllerViewController

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
    NSLog(@"tabBar didSelectItem");
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    NSLog(@"tabBarController didSelectViewController");
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.tabBarController.delegate = self; // Tried it both with and without this.
}

显示UITabBarcontroller很好,带有标签栏。单击选项卡会触发didSelectItem,但不会触发didSelectViewController,这是我需要处理的事件。UITabBarcontroller正在加载并显示UIViewController.

更新self.tabBarController.delegate = self将该行更改为self.delegate = self有效,并且都触发。我不明白为什么这是必要的。设置self.delegate = self似乎......愚蠢。有任何想法吗?

4

1 回答 1

0

只需将标题更改如下:

#import <UIKit/UIKit.h>

@interface PFXTabControllerViewController : **UIViewController** <UITabBarControllerDelegate>
@end
于 2013-02-02T03:31:43.923 回答