uni-app vc isKindOfClass 闪退

uni-app vc isKindOfClass 闪退

开发环境 版本号 项目创建方式
Mac 13.1 HBuilderX
  • 产品分类:uniapp/App
  • PC开发环境操作系统:Mac
  • HBuilderX类型:正式
  • HBuilderX版本号:3.8.12
  • 手机系统:iOS
  • 手机系统版本号:iOS 13.2
  • 手机厂商:苹果
  • 手机机型:iphone6s
  • 页面类型:vue
  • vue版本:vue2
  • 打包方式:云端

操作步骤:

  • isKindOfClass 闪退

预期结果:

  • isKindOfClass 闪退

实际结果:

  • isKindOfClass 闪退

bug描述:

  • (UIViewController *)findCurrentShowingViewControllerFrom:(UIViewController *)vc { // 递归方法 Recursive method UIViewController *currentShowingVC; if ([vc presentedViewController]) { // 当前视图是被presented出来的 UIViewController *nextRootVC = [vc presentedViewController]; currentShowingVC = [self findCurrentShowingViewControllerFrom:nextRootVC];
    } else if ([vc isKindOfClass:[UITabBarController class]]) { // 根视图为UITabBarController UIViewController *nextRootVC = [(UITabBarController *)vc selectedViewController]; currentShowingVC = [self findCurrentShowingViewControllerFrom:nextRootVC];
    } else if ([vc isKindOfClass:[UINavigationController class]]){ // 根视图为UINavigationController UIViewController *nextRootVC = [(UINavigationController *)vc visibleViewController]; currentShowingVC = [self findCurrentShowingViewControllerFrom:nextRootVC];
    } else { // 根视图为非导航类 currentShowingVC = vc; }

    return currentShowingVC;
    }

isKindOfClass 闪退


更多关于uni-app vc isKindOfClass 闪退的实战教程也可以访问 https://www.itying.com/category-93-b0.html

5 回复

错误日志的截图发一下

更多关于uni-app vc isKindOfClass 闪退的实战教程也可以访问 https://www.itying.com/category-93-b0.html


图片放下边了,加你好友没有回复

这个是手机上运行的日志

麻烦看一下

这个闪退问题通常是由于在原生插件或扩展代码中调用了isKindOfClass:方法,但传入的vc参数可能为nil或无效对象导致的。建议检查以下几点:

  1. 确保vc参数不为nil,可以在方法开头添加空值判断:
if (!vc) return nil;
  1. 检查调用栈,确认该方法是在什么情况下被调用的,以及传入的vc对象是否有效

  2. 如果是原生插件代码,建议使用try-catch捕获异常:

@try {
    if ([vc isKindOfClass:[UITabBarController class]]) {
        //...
    }
} @catch (NSException *exception) {
    NSLog(@"isKindOfClass crash: %@", exception);
}
  1. 考虑使用更安全的判断方式:
if ([vc respondsToSelector:[@selector](/user/selector)(selectedViewController)]) {
    // 可能是UITabBarController
}
回到顶部