V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
Dean
V2EX  ›  iDev

iOS 一个困惑很久提示"invalid mode"的崩溃

  •  
  •   Dean · 2016-12-19 18:31:20 +08:00 · 40229 次点击
    这是一个创建于 2677 天前的主题,其中的信息可能已经有所发展或是发生改变。

    ##下面是异常出现后定位的代码,反复审查后没有发现问题

    此处 QRCodePopupViewController 只是普通 ViewController ,主要是是想使用 addChildViewController 弹出卡片式窗口,之前在其他模块写过同样的代码没有任何问题,此处并没有任何影响 RunLoop 的 Mode 逻辑代码,虽然定位在这里但是真没发现问题。。。

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        [tableView deselectRowAtIndexPath:indexPath animated:NO];
        QRCodePopupViewController *popupVC = [[QRCodePopupViewController alloc] init];
        [self addChildViewController:popupVC];
        [self.view addSubview:popupVC.view];
        
        [self presentViewController:popupVC animated:NO completion:^{
            
        }];
    }
    

    ##抛出的异常日志

    invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific
    
    15 条回复    2017-11-06 16:30:27 +08:00
    SeanChense
        1
    SeanChense  
       2016-12-19 18:36:11 +08:00 via iPhone
    代码抠出来放一个小工程看看
    anerevol
        2
    anerevol  
       2016-12-19 18:40:28 +08:00
    能把日志异常贴全一点么
    anerevol
        3
    anerevol  
       2016-12-19 18:44:12 +08:00
    参考这样的 https://madordie.github.io/2016/10/12/debug-note/
    invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific 这句应该和 crash 本身没关系
    Dean
        4
    Dean  
    OP
       2016-12-19 18:49:43 +08:00
    @anerevol 其实日志有用的已经贴出了 invalid mode 'kCFRunLoopCommonModes' provided to CFRunLoopRunSpecific - break on _CFRunLoopError_RunCalledWithInvalidMode to debug. This message will only appear once per execution.
    libc++abi.dylib: terminate_handler unexpectedly threw an exception
    bzmario
        5
    bzmario  
       2016-12-19 21:24:49 +08:00
    已经添加为子视图、子控制器了,还 present 做什么
    mornlight
        6
    mornlight  
       2016-12-19 21:50:09 +08:00
    用 storyboard 了吗,检测一遍关联有没有问题
    Dean
        7
    Dean  
    OP
       2016-12-20 01:08:55 +08:00
    @mornlight 与关联无关
    Dean
        8
    Dean  
    OP
       2016-12-20 01:09:21 +08:00
    ahmiao
        9
    ahmiao  
       2016-12-20 08:32:33 +08:00
    present 之前不需要 addChildViewController 跟 addSubview 吧
    Dean
        10
    Dean  
    OP
       2016-12-20 09:36:58 +08:00
    @ahmiao 看 demo
    hekunhotmail
        11
    hekunhotmail  
       2016-12-20 10:50:50 +08:00
    [self addChildViewController:popupVC];
    [self.view addSubview:popupVC.view];
    [self presentViewController:popupVC animated:NO completion:^{

    }];

    你这里调用了系统的 presentViewController 还是重写了?
    如果是调用系统的 presentViewController 你知道 presentViewController 里面都干了什么?
    crashX
        12
    crashX  
       2016-12-20 12:45:26 +08:00
    你的 xib 或者 storyboard 关联的 IBOutlet 有问题,检查一下 xib 是否有 warning 。 xib 是大坑,强烈不建议用。
    Dean
        13
    Dean  
    OP
       2016-12-20 14:10:08 +08:00
    ### 重新更新
    > 由于之前写的代码没有备注,拷贝丢失建立 NavigationController 部分, prsentViewController 部分一直怪怪的,思维短路没发现😂

    ```objc
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    QRCodePopupViewController *popupVC = [[QRCodePopupViewController alloc] init];
    [self addChildViewController:popupVC];
    [self.view addSubview:popupVC.view];

    UINavigationController *popupVN = [[UINavigation controller] initWithRootController:popupVC];

    [self presentViewController:popupVN animated:NO completion:^{

    }];
    }
    ```
    kobe1941
        14
    kobe1941  
       2016-12-20 19:18:03 +08:00
    这两行完全多余啊:
    [self addChildViewController:popupVC];
    [self.view addSubview:popupVC.view];
    yuzhouwww
        15
    yuzhouwww  
       2017-11-06 16:30:27 +08:00
    我这边是使用了无效的 IBOutlet 指针
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3286 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 12:38 · PVG 20:38 · LAX 05:38 · JFK 08:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.