在后台执行某些操作后从导航控制器推送

时间:2014-09-18 10:55:46

标签: ios core-data objective-c-blocks nsoperationqueue

我创建了一种方法,可以在后台执行某些操作并在前景中操作ui。在后台我现在仍然什么都不做/但后来我想拿一个核心数据对象和前台我从主动导航控制器推送。

当我这样做时,我收到了这个错误:

  

由于未捕获的异常终止应用' NSInvalidArgumentException',原因:' - [__ NSArrayM insertObject:atIndex:]:object不能为nil'

这是我的一段代码:

[[NSOperationQueue new] addOperationWithBlock:^{
    [[NSOperationQueue mainQueue]addOperationWithBlock:^{
        //theCatalog is not nil here just FYI
        PO1(theCatalog); //just for log the catalog object
        [theCatalog showImageForThisCatalogwithNavigationController:self.delegateBGCatalogSearchTableCellResultProtocol.navigationController withPage:pageNumber];
    }];
}];

但是当我打电话给我时,我的代码并没有像这样给出错误。

  [theCatalog showImageForThisCatalogwithNavigationController:self.delegateBGCatalogSearchTableCellResultProtocol.navigationController withPage:pageNumber];

基本上,代码根本不会在任何块中运行。

我可以跑

   [theCatalog showImageForThisCatalogwithNavigationController:self.delegateBGCatalogSearchTableCellResultProtocol.navigationController withPage:pageNumber]; just fine

如果我跑

    [[NSOperationQueue mainQueue]addOperationWithBlock:^{
            [theCatalog showImageForThisCatalogwithNavigationController:self.delegateBGCatalogSearchTableCellResultProtocol.navigationController withPage:pageNumber];
        //theCatalog is not nil here just FYI
    }];

这几乎是等价的,然后我得到了那个错误。我不知道错误在哪里。我刚刚被重定向到main()并且程序崩溃了。

这是完整的错误代码

2014-09-18 18:15:52.808 [1735:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil'
*** First throw call stack:
(0x2f262fd3 0x39a0fccf 0x2f19cf9d 0x31b15c6f 0x31b15aab 0x31b15633 0x31b2cf49 0x31b2cb8d 0x31b2cb25 0x31a7ed79 0x316fc62b 0x316f7e3b 0x316f7ccd 0x316f76df 0x316f74ef 0x316f121d 0x2f22e2a5 0x2f22bc49 0x2f22bf8b 0x2f196f4f 0x2f196d33 0x3409b663 0x31ae216d 0xc91cd 0x39f1cab7)

也许下面的数字首先抛出调用堆栈,(0x2f262fd3 0x39a0fccf 0x2f19cf9d 0x31b15c6f 0x31b15aab 0x31b15633 0x31b2cf49 0x31b2cb8d 0x31b2cb25 0x31a7ed79 0x316fc62b 0x316f7e3b 0x316f7ccd 0x316f76df 0x316f74ef 0x316f121d 0x2f22e2a5 0x2f22bc49 0x2f22bf8b 0x2f196f4f 0x2f196d33 0x3409b663 0x31ae216d 0xc91cd 0x39f1cab7)可能有助于调试,但我不知道它们是什么。     libc ++ abi.dylib:以NSException类型的未捕获异常终止

现在我得到了另一个第一个抛出调用堆栈,如2014-09-19 14:13:19.595[18059:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSArrayM insertObject:atIndex:]: object cannot be nil' *** First throw call stack: ( 0 CoreFoundation 0x05e501e4 __exceptionPreprocess + 180 1 libobjc.A.dylib 0x02c258e5 objc_exception_throw + 44 2 CoreFoundation 0x05e02abc -[__NSArrayM insertObject:atIndex:] + 844 3 CoreFoundation 0x05e02760 -[__NSArrayM addObject:] + 64 4 UIKit 0x012e8050 -[UINavigationBar pushNavigationItem:] + 244 5 UIKit 0x012e73b7 -[UINavigationBar _pushNavigationItem:transition:] + 429 6 UIKit 0x01389fee __71-[UINavigationController pushViewController:transition:forceImmediate:]_block_invoke + 207 7 UIKit 0x01388a2d -[UINavigationController _startDeferredTransitionIfNeeded:] + 998 8 UIKit 0x013894e9 -[UINavigationController __viewWillLayoutSubviews] + 57 9 UIKit 0x014ca0d1 -[UILayoutContainerView layoutSubviews] + 213 10 UIKit 0x11ebd21b -[UILayoutContainerViewAccessibility(SafeCategory) layoutSubviews] + 50 11 UIKit 0x012b1964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355 12 libobjc.A.dylib 0x02c3782b -[NSObject performSelector:withObject:] + 70 13 QuartzCore 0x00f3b45a -[CALayer layoutSublayers] + 148 14 QuartzCore 0x00f2f244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380 15 QuartzCore 0x00f2f0b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26 16 QuartzCore 0x00e957fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294 17 QuartzCore 0x00e96b85 _ZN2CA11Transaction6commitEv + 393 18 QuartzCore 0x00e97258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92 19 CoreFoundation 0x05e1836e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30 20 CoreFoundation 0x05e182bf __CFRunLoopDoObservers + 399 21 CoreFoundation 0x05df6254 __CFRunLoopRun + 1076 22 CoreFoundation 0x05df59d3 CFRunLoopRunSpecific + 467 23 CoreFoundation 0x05df57eb CFRunLoopRunInMode + 123 24 GraphicsServices 0x034f95ee GSEventRunModal + 192 25 GraphicsServices 0x034f942b GSEventRun + 104 26 UIKit 0x01242f9b UIApplicationMain + 1225 27 0x0000291d main + 141 28 libdyld.dylib 0x03118701 start + 1 29 ??? 0x00000001 0x0 + 1 )

0 个答案:

没有答案