从弧ViewController中呈现非弧ViewController

时间:2013-01-21 03:49:35

标签: iphone ios objective-c automatic-ref-counting

- 集成到主应用程序后的更新名称和添加后退 -

我有一个简单的iOS应用程序,它由两个控制器组成:

  1. BXDemoViewController 不使用ARC
  2. 使用ARC 的TestViewController。
  3. 我试图使用以下代码在TestViewController中呈现BXDemoViewController 在触摸UIButton时调用:

    -(IBAction) invokeScanner: (id)sender {
        BXDemoViewController * scannerController = [[BXDemoViewController alloc] init];
        [self presentViewController:scannerController animates:YES completion:nil];
    }
    

    控制器被正确调用并且运行良好,但是当dismissViewControllerAnimated时: 得到一个EXEC_BAD_ACCESS。将呈现控制器(TestViewController)转换为 非ARC代码摆脱了问题,这表明它与我的方式有关 分配和使用BXDemoViewController,但我想将TestViewController保留在ARC中。

    我对iOS开发相对较新,而我的有限知识告诉我,我想以某种方式 桥接BXDemoViewController,因为它在ARC控制的源中调用,但我不知道如何。

    非常感谢任何帮助。

    Backtrace输出:

    thread #1: tid = 0x2503, 0x32d5f5b0 libobjc.A.dylib`objc_msgSend + 16, stop reason = EXC_BAD_ACCESS (code=1, address=0x8002b192)
    frame #0: 0x32d5f5b0 libobjc.A.dylib`objc_msgSend + 16
    frame #1: 0x31df0b5e CoreFoundation`+[__NSArrayI __new:::] + 58
    frame #2: 0x31df03b6 CoreFoundation`-[__NSPlaceholderArray initWithObjects:count:] + 270
    frame #3: 0x39682fe6 UIKit`-[UIView dealloc] + 98
    frame #4: 0x32d61488 libobjc.A.dylib`(anonymous namespace)::AutoreleasePoolPage::pop(void*) + 168
    frame #5: 0x31de9440 CoreFoundation`_CFAutoreleasePoolPop + 16
    frame #6: 0x31e79f40 CoreFoundation`__CFRunLoopRun + 1296
    frame #7: 0x31decebc CoreFoundation`CFRunLoopRunSpecific + 356
    frame #8: 0x31decd48 CoreFoundation`CFRunLoopRunInMode + 104
    frame #9: 0x39bea2ea GraphicsServices`GSEventRunModal + 74
    frame #10: 0x396a82f8 UIKit`UIApplicationMain + 1120
    frame #11: 0x00002296 BXDemo`main + 90 at main.m:15
    
    thread #3: tid = 0x2903, 0x31084648 libsystem_kernel.dylib`kevent64 + 24
    frame #0: 0x31084648 libsystem_kernel.dylib`kevent64 + 24
    frame #1: 0x344a54f0 libdispatch.dylib`_dispatch_mgr_invoke + 796
    frame #2: 0x34497df8 libdispatch.dylib`_dispatch_mgr_thread$VARIANT$up + 36
    
    thread #5: tid = 0x2b03, 0x31083eb4 libsystem_kernel.dylib`mach_msg_trap + 20
    frame #0: 0x31083eb4 libsystem_kernel.dylib`mach_msg_trap + 20
    frame #1: 0x3108404c libsystem_kernel.dylib`mach_msg + 40
    frame #2: 0x31e7b044 CoreFoundation`__CFRunLoopServiceMachPort + 128
    frame #3: 0x31e79da2 CoreFoundation`__CFRunLoopRun + 882
    frame #4: 0x31decebc CoreFoundation`CFRunLoopRunSpecific + 356
    frame #5: 0x31decd48 CoreFoundation`CFRunLoopRunInMode + 104
    frame #6: 0x36148a44 WebCore`RunWebThread(void*) + 444
    frame #7: 0x344df310 libsystem_c.dylib`_pthread_start + 308
    frame #8: 0x344df1d8 libsystem_c.dylib`thread_start + 8
    
    thread #6: tid = 0x2427, 0x3109408c libsystem_kernel.dylib`__psynch_cvwait + 24
    frame #0: 0x3109408c libsystem_kernel.dylib`__psynch_cvwait + 24
    frame #1: 0x344d7d2e libsystem_c.dylib`_pthread_cond_wait + 646
    frame #2: 0x344e1f18 libsystem_c.dylib`pthread_cond_wait + 40
    frame #3: 0x381f39a8 CoreMedia`FigSemaphoreWaitRelative + 260
    frame #4: 0x3499035a MediaToolbox`fpa_AsyncMovieControlThread + 26
    frame #5: 0x3821198a CoreMedia`figThreadMain + 194
    frame #6: 0x344df310 libsystem_c.dylib`_pthread_start + 308
    frame #7: 0x344df1d8 libsystem_c.dylib`thread_start + 8
    
    thread #9: tid = 0x2e03, 0x000aa468 BXDemo`BitmapIsPixelOn(tagBITMAP const&, long, long) + 60
    frame #0: 0x000aa468 BXDemo`BitmapIsPixelOn(tagBITMAP const&, long, long) + 60
    frame #1: 0x000a9df2 BXDemo`PointMoveTillOffNoisy(tagPOINT&, Direction, tagBITMAP&, long, long) + 290
    frame #2: 0x0007f966 BXDemo`ReaderDataMatrix::FindBarcodeBoundaries(tagBITMAP&, tagPOINT, tagPOINT, _BCDM*, signed char) + 3278
    frame #3: 0x0007df6c BXDemo`ReaderDataMatrix::DMBarcodeRecognition(BarcodeReaderInfo&, tagBITMAP&) + 324
    frame #4: 0x0007de08 BXDemo`ReaderDataMatrix::Recognize(BarcodeReaderInfo&, tagBITMAP&, BarcodeResultList&) + 236
    frame #5: 0x000abba2 BXDemo`BarcodeReader::PerformRecognition(tagBITMAP&) + 686
    frame #6: 0x000ab858 BXDemo`BarcodeReader::AnalyzeBarcode(ImageBase*, long, long*) + 112
    frame #7: 0x000ab186 BXDemo`BXiOSAPI::recognize(void const*, int, int, long, long, bool, IOSResult&) + 398
    frame #8: 0x000af860 BXDemo`-[BXRuntime RecognizeImage:width:height:stride:result:] + 244 at BXRuntime.mm:630
    frame #9: 0x000ae2ee BXDemo`-[BXRuntime recognizeData:] + 234 at BXRuntime.mm:215
    frame #10: 0x000b11cc BXDemo`-[BXThreadQueue dispatchThread:] + 296 at BXThreadQueue.mm:133
    frame #11: 0x33a9067c Foundation`__NSThread__main__ + 972
    frame #12: 0x344df310 libsystem_c.dylib`_pthread_start + 308
    frame #13: 0x344df1d8 libsystem_c.dylib`thread_start + 8
    
    thread #10: tid = 0x2f03, 0x344d489c libsystem_c.dylib`start_wqthread
    frame #0: 0x344d489c libsystem_c.dylib`start_wqthread
    

1 个答案:

答案 0 :(得分:0)

使用以下方法

将非弧视图控制器转换为弧控制器

目标 - >编译器源 - >双击非ARC Viewcontroller的.m文件,并将标志设为-fno-objc-arc。现在它会正常工作。