OStack程序员社区-中国程序员成长平台

标题: iphone - CustomTabBarController 未响应委托(delegate)回调 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 16:36
标题: iphone - CustomTabBarController 未响应委托(delegate)回调

我使用 Martin 的 tutorial 创建了一个自定义 UITabBarController . 我的子类 FSTabBarController 在 View Controller 之间切换,并且在我所见的范围内表现正常。

问题是,当我将 tabBarContoller 更改为我的子类时,它不会响应我的委托(delegate);

- (void)tabBarControllerUITabBarController *)tabBarController didSelectViewControllerUIViewController *)viewController

如果我将它改回 UITabBarController - 当我使用默认的 UITabBarController - 委托(delegate)会正常工作。

自定义子类使用以下函数来表示选项卡选择:

- (void)_buttonClickedid)sender
{
    self.selectedIndex = [sender tag];
    [self _updateTabImage];
}

编辑:

AppDelegate.h

...
@interface AppDelegate : UIResponder <UIApplicationDelegate,UITabBarControllerDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) FSTabBarController *tabBarController;

AppDelegate.m

- (BOOL)applicationUIApplication *)application didFinishLaunchingWithOptionsNSDictionary *)launchOptions
{
...
    self.tabBarController = [[FSTabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:peopleViewController,viewController,profileViewController, nil];
    self.tabBarController.delegate = self;
...
}

- (void)tabBarControllerUITabBarController *)tabBarController didSelectViewControllerUIViewController *)viewController
{
   // not called when FSTabBarController, called when UITabBarController !!
}



Best Answer-推荐答案


好的,从他的站点下载示例并进行测试。 是的,您需要从子类手动调用委托(delegate):

这就是你应该如何改变 buttonClicked 函数:

- (void)_buttonClickedid)sender
{
    self.selectedIndex = [sender tag];
    if (self.delegate) {
        [self.delegate tabBarController:self didSelectViewController:self.selectedViewController];
    }
    [self _updateTabImage];
}

关于iphone - CustomTabBarController 未响应委托(delegate)回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12548699/






欢迎光临 OStack程序员社区-中国程序员成长平台 (http://ostack.cn/) Powered by Discuz! X3.4