BCTabBarController 中未调用 viewWillAppear

发布于 2024-12-29 06:07:39 字数 1494 浏览 4 评论 0原文

我有一个大型项目,客户希望自定义标签栏。我选择 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.

我已 将问题发布到 github 存储库< /a> 的 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 中

I've large project where customer want's to customize tabbar. I've choose BCTabBarController to replace UITabbarController. After few fixes it works fine but after testing I found one bug:

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.

I've posted issue to github repo of briancolins, but still have no answer.

Here some code where I calling present modal view controller:

    - (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];
    }
}

UPDATE: this issue not reproduced in iOS5 but present at iOS 4.3

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

世俗缘 2025-01-05 06:07:39

正如你所指出的。 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.

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

As you indicated. iOS 5 forwards the messages, where previous versions do not. Here's how I handle a similar situation:

- (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.

In my situation I have a list of view controllers that could be visible, so I manage which view controller is visible and forward the message to it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文