【问题标题】:Tapping TabBar crashes App点击 TabBar 会导致 App 崩溃
【发布时间】:2015-02-25 20:40:15
【问题描述】:

我的应用程序出现了一个非常奇怪的错误。该应用程序有两个选项卡。选项卡二显示报告列表。如果我在选项卡二中点击其中一个报告,应用程序会正确显示报告的详细信息。然后我点击标签一并立即点击标签二。该应用在 iOS 8 中崩溃,但在 iOS 7 中运行良好。

如果我在点击 Tab 1 之前返回到 Tab 2 的根视图控制器,再次点击 Tab 2 不会使应用程序崩溃。知道什么可能导致此错误吗?

在 AppDelegate 类中,我有以下代码:

- (BOOL)tabBarController:(UITabBarController *)tabBarController
shouldSelectViewController:(UIViewController *)viewController
{
    UIViewController *currentController = tabBarController.selectedViewController;
    if ([currentController isKindOfClass:[UINavigationController class]])
        [(UINavigationController *)currentController popToRootViewControllerAnimated:NO];

    return YES;
}

【问题讨论】:

  • 我放了一个 if 语句来检查手机是否运行 iOS 8。应用程序已经停止崩溃。仍然不确定为什么 iOS 8 的代码会崩溃。

标签: tabbar


【解决方案1】:

我通过在代码上添加 if 语句解决了崩溃问题,如下所示。仍然不确定为什么代码在 iOS 8 中崩溃。

- (BOOL)tabBarController:(UITabBarController *)tabBarController
shouldSelectViewController:(UIViewController *)viewController
{

    #define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

    if (SYSTEM_VERSION_LESS_THAN(@"8.0"))
    {
        NSLog(@"The iOS is less than 8");

        UIViewController *currentController = tabBarController.selectedViewController;
        if ([currentController isKindOfClass:[UINavigationController class]])
            [(UINavigationController *)currentController popToRootViewControllerAnimated:NO];

        return YES;
    }


    return YES;

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-10
    • 1970-01-01
    • 2018-02-07
    • 1970-01-01
    • 1970-01-01
    • 2021-04-14
    相关资源
    最近更新 更多