这是我的app-delegate.m的代码存根 - 它永远不会被调用。
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
NSLog(@"%s", __FUNCTION__);
}
它在此app-delegate.h中定义
@interface OrioleAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> {
UIWindow *window;
UITabBarController *tabBarController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@end
答案 0 :(得分:15)
您是否在UITabBarController
和申请代表之间建立了联系?
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
...
tabBarController.delegate = self;
...
}
答案 1 :(得分:15)
如果您的ViewController是UITabBarController
,则需要将self设置为委托,因为您无法直接更改UITabBar
的委托。
例如,在UITabBarController
的ViewDidLoad中:
- (void)viewDidLoad
{
[super viewDidLoad];
self.delegate = self;
}
答案 2 :(得分:0)
我添加了以下tabBarController.delegate = self;
,一切都很顺利。我希望这对其他人有帮助。
- (void)applicationDidFinishLaunching:(UIApplication *)application {
// Add the tab bar controller's current view as a subview of the window
tabBarController.delegate = self;
[window addSubview:tabBarController.view];
}