无法使用TabBar委托方法 [英] Cant use TabBar delegate methods

查看:103
本文介绍了无法使用TabBar委托方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有自定义TabBar控制器类的应用.

I got an app with my custom TabBar Controller Class.

我试图实现标签栏控制器委托方法:

I tried to implement tabbar controller delegate method:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    NSLog(@"%i",tabBarController.selectedIndex);
}

但是它不起作用.为什么?

But it doesnt work. Why?

ViewDidLoad中我写道:

self.tabBarController.delegate = self;

在.h中,我实现了:

@interface BaseViewController : UITabBarController <UITabBarControllerDelegate>

推荐答案

在自定义TabBarController中,请勿使用

In your custom TabBarController, do not use

self.tabBarController.delegate = self;

但是使用

self.delegate = self;

.tabBarController返回视图控制器层次结构中最接近的祖先,它是一个标签栏控制器,但是您自定义的TabBarController是您要定位的控制器,因此无需在其层次结构中进行搜索

.tabBarController returns the nearest ancestor in the view controller hierarchy that is a tab bar controller, but your custom TabBarController IS the controller you want to target, so no need to search in its hierarchy

这篇关于无法使用TabBar委托方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆