代码之家  ›  专栏  ›  技术社区  ›  Chintan Patel

无法识别发送到实例的选择器。为随机对象调用的方法

  •  2
  • Chintan Patel  · 技术社区  · 14 年前

    好吧,这让我像那个家伙一样被彻底打败了 here 有确切的问题。

    我有一个 UITableView 在视图控制器中有一些支持自动旋转的行,有时,如果我旋转手机,我会得到“exc_bad_access”,有时我会得到一个类似以下的堆栈跟踪:

    2010-11-19 16:51:05.634 [2306:307] -[CABasicAnimation numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x58207d0
    2010-11-19 16:51:05.688 [2306:307] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CABasicAnimation numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x58207d0'
    *** Call stack at first throw:
    (
     0   CoreFoundation                      0x344aaed3 __exceptionPreprocess + 114
     1   libobjc.A.dylib                     0x33975811 objc_exception_throw + 24
     2   CoreFoundation                      0x344ac683 -[NSObject(NSObject) doesNotRecognizeSelector:] + 102
     3   CoreFoundation                      0x344541d9 ___forwarding___ + 508
     4   CoreFoundation                      0x34453f90 _CF_forwarding_prep_0 + 48
     5   UIKit                               0x31b20717 -[UITableViewRowData(UITableViewRowDataPrivate) _updateNumSections] + 66
     6   UIKit                               0x31b20677 -[UITableViewRowData invalidateAllSections] + 50
     7   UIKit                               0x31b2048d -[UITableView(_UITableViewPrivate) _updateRowData] + 64
     8   UIKit                               0x31b22941 -[UITableView(_UITableViewPrivate) _ensureRowDataIsLoaded] + 24
     9   UIKit                               0x31b22909 -[UITableView numberOfSections] + 16
     10  UIKit                               0x31bd114f -[UISearchDisplayController _updateNoSearchResultsMessageVisiblity] + 54
     11  UIKit                               0x31cfbef7 -[UISearchDisplayController windowWillAnimateRotation:] + 478
     12  Foundation                          0x3325d6b3 _nsnote_callback + 142
     13  CoreFoundation                      0x34431713 __CFXNotificationPost_old + 402
     14  CoreFoundation                      0x344313b3 _CFXNotificationPostNotification + 118
     15  Foundation                          0x3324cdb7 -[NSNotificationCenter postNotificationName:object:userInfo:] + 70
     16  UIKit                               0x31b5dbb7 -[UIWindow _setRotatableClient:toOrientation:duration:force:] + 3114
     17  UIKit                               0x31b64013 -[UIWindow _setRotatableViewOrientation:duration:force:] + 50
     18  UIKit                               0x31b39a0f -[UIWindow _updateToInterfaceOrientation:duration:force:] + 74
     19  UIKit                               0x31b39be9 -[UIWindow _updateInterfaceOrientationFromDeviceOrientation:] + 112
     20  UIKit                               0x31b39b15 -[UIWindow _handleDeviceOrientationChange:] + 88
     21  Foundation                          0x3325d6b3 _nsnote_callback + 142
     22  CoreFoundation                      0x34431713 __CFXNotificationPost_old + 402
     23  CoreFoundation                      0x344313b3 _CFXNotificationPostNotification + 118
     24  Foundation                          0x3324cdb7 -[NSNotificationCenter postNotificationName:object:userInfo:] + 70
     25  UIKit                               0x31b0d0ed -[UIDevice setOrientation:animated:] + 144
     26  UIKit                               0x31b2a51b -[UIApplication handleEvent:withNewEvent:] + 2738
     27  UIKit                               0x31b29901 -[UIApplication sendEvent:] + 44
     28  UIKit                               0x31b29337 _UIApplicationHandleEvent + 5110
     29  GraphicsServices                    0x3026c04b PurpleEventCallback + 666
     30  CoreFoundation                      0x3443fce3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 26
     31  CoreFoundation                      0x3443fca7 __CFRunLoopDoSource1 + 166
     32  CoreFoundation                      0x3443256d __CFRunLoopRun + 520
     33  CoreFoundation                      0x34432277 CFRunLoopRunSpecific + 230
     34  CoreFoundation                      0x3443217f CFRunLoopRunInMode + 58
     35  GraphicsServices                    0x3026b5f3 GSEventRunModal + 114
     36  GraphicsServices                    0x3026b69f GSEventRun + 62
     37  UIKit                               0x31ad0123 -[UIApplication _run] + 402
     38  UIKit                               0x31ace12f UIApplicationMain + 670
     39  App                                 0x0000285f main + 70
     40  App                            0x00002814 start + 40
    )
    terminate called after throwing an instance of 'NSException'
    Program received signal:  “SIGABRT”.
    

    在这种情况下是 CABasicAnimation 在哪 numberOfSectionsInTableView 正在被调用,但有时类名如下 NSMachPort 我从未听说过。另外,正在调用的方法 节数表格视图 保持不变,类名更改为始终 doesNotRecognizeSelector 例外。

    而且这个问题只在我试图旋转设备时发生。每当我得到如上所述的堆栈跟踪时,所有的系统函数都会使调试变得困难。

    真的需要专家的建议。请阅读上面提到的论坛以明确这个问题。

    2 回复  |  直到 13 年前
        1
  •  1
  •   Joshua Weinberg    14 年前

    从启用nszombies开始。听起来像是你在释放一个物体。

        2
  •  2
  •   Chintan Patel    14 年前

    哇!我以为我对僵尸足够了解,但我错了!

    我启用了Nszombies,这让我:

    *** -[ContactsViewController numberOfSectionsInTableView:]: message sent to deallocated instance 0x88dafa0
    

    执行“po 0x88dafa0”将无法工作,因为该对象的内存已被释放。

    一些谷歌搜索让我 this 作者描述了如何查找释放/释放的对象。我们只需要在要在环境中设置的变量中将mallocstacklogginnocompact设置为1,并启用nszombieEnabled。

    我得到的输出 info malloc-history 0xf270740 命令有一行:

    -[VoicePlayController actionSheet:clickedButtonAtIndex:] at /Users/Documents/Xcode Projects/Classes/VoicePlayController.m:454
    

    那一行的代码是:

    contactsViewController = [[ContactsViewController alloc] initWithNibName:@"ContactsViewController" bundle:nil];
    

    我感动了 [contactsViewController release]; 线到 dealloc 方法,而不是紧随其后 [self.navigationController presentModalViewController:contactsViewController animated:YES]; 问题解决了!