ios - shouldSelectViewController 没有被调用

标签 ios uitabbarcontroller uitabbar appdelegate

我正在尝试调用我的 shouldSelectViewController 委托(delegate)函数。但它似乎不起作用。

我做了以下操作,但函数仍然没有被调用

.h

@interface myAppDelegate : UIResponder <UIApplicationDelegate, UITabBarControllerDelegate>

@property (strong, nonatomic) UIWindow *window;

@end

.m

@implementation TakeFiveCameraAppDelegate

@synthesize window;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{   
    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
    tabBarController.delegate = (id)self;
    return YES;
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    NSLog(@"test");
    return YES;
}

@end

我不确定我在这里遗漏了什么。

最佳答案

加入viewDidLoad

[ self 设置委托(delegate): self ];

关于ios - shouldSelectViewController 没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16082061/

相关文章:

ios - 应用内支付仍然说它处于沙盒模式

ios - 获取细胞索引-偷看和流行

ios - 点击标签栏项目滚动顶部

c# - MonoTouch 中自定义 TabBarController 中的 ViewDidLoad 中的公共(public)属性始终为 null

iphone - 为 iPhone 应用程序创建自定义 UITabBar 真的很酷吗?

ios - iPad 应用程序中标签栏内的 Split View

iphone - 更改 tabbaritem 的字体大小

ios - 如何将应用程序图标包含到我的 Xcode 项目中

ios - 尝试呈现其 View 不在窗口层次结构中的 UIViewController

ios - UINavigationController 为 NULL