【问题标题】:viewWillAppear not called in BCTabBarController在 BCTabBarController 中未调用 viewWillAppear
【发布时间】:2012-02-19 13:26:23
【问题描述】:

我有一个客户想要自定义标签栏的大型项目。我选择 BCTabBarController 来代替 UITabbarController。经过几次修复后它工作正常,但经过测试我发现了一个错误:

ViewWillAppear, ViewDidAppear, ViewWillDisappear ViewDidDisappear methods not called in selectded view controller and not called into BCTabBarController.
This problem appears after BCTabBarController show modal controller from instance of BCTabBarController class.

我有 posted issue to github repo 的 briancolins,但仍然没有答案。

这里有一些我调用当前模态视图控制器的代码:

    - (void) presentProperlyModalViewController:(UIViewController *)modalViewController animated:(BOOL)animated
{
    if ([[self controllerToPresentModalFrom] respondsToSelector:@selector(presentViewController:animated:completion:)]) // For iOS 5
    {
        [[self controllerToPresentModalFrom] presentViewController:modalViewController animated:animated completion:^(){}];
    }
    else
    {
        [[self controllerToPresentModalFrom] presentModalViewController:modalViewController animated:animated];
    }
}

-(void) dismissProperlyModalViewControllerAnimated:(BOOL)animated
{
    if ([self respondsToSelector:@selector(dismissViewControllerAnimated:completion:)]) {
        [self dismissViewControllerAnimated:animated completion:^(){}];
    }
    else
    {
        [self dismissModalViewControllerAnimated:YES];
    }
}

更新:此问题未在 iOS5 中重现,但在 iOS 4.3 中存在

【问题讨论】:

    标签: objective-c ios ios4 uitabbarcontroller


    【解决方案1】:

    正如你所说。 iOS 5 会转发消息,而以前的版本则不会。以下是我处理类似情况的方法:

    - (BOOL)needsMessageForwarding:(UIViewController *)vc {
        if ( [vc isKindOfClass:[UINavigationController class]] == NO)
            return YES;
    
        NSString *ver = [UIDevice currentDevice].systemVersion;
        if ( [ver characterAtIndex:0 < '5'] )
            return YES;
    
        return NO;
    }
    
    - (void) viewWillAppear:(BOOL)animated {
        ...
        if ( [self needsMessageForwarding:modalViewController] )
            [modalViewController viewWillAppear:animated];
        ...
    }
    
    // repeat pattern in the other viewWill... viewDid... functions.
    

    在我的情况下,我有一个可见的视图控制器列表,因此我管理哪个视图控制器可见并将消息转发给它。

    【讨论】:

    • 我想通了。这是 BCTabBarController 中的一个错误。有 childViewController 数组。如果已提交 - viewwillAppear 不会发送。
    • 谢谢!我使用的是对选择器的响应
    猜你喜欢
    • 1970-01-01
    • 2012-08-26
    • 1970-01-01
    • 1970-01-01
    • 2014-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多