viewWillAppear未在BCTabBarController中调用

时间:2012-01-26 12:51:55

标签: objective-c ios ios4 uitabbarcontroller

我有一个大型项目,客户希望自定义tabbar。我选择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中出现

1 个答案:

答案 0 :(得分:0)

如你所说。 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.

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

相关问题