UITableViewCell无法识别的选择器

时间:2011-12-04 22:56:35

标签: iphone uitableview

我有一个带有ViewController的UITableView作为其数据源和委托。在同一个XIB中,我的搜索栏有一个自定义单元格。表视图中的第一个单元格是此单元格。偶尔,我遇到了以下例外的崩溃:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCell numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x5d76840'

Gdb显示这实际上是我的搜索单元格,并且它是tableview的子代。此外,进一步检查显示数据源实际上正确指向我的视图控制器而不是搜索栏单元格。基于此,似乎UIKit只是将消息发送到错误的目标。以前见过这样的人吗?它只是模拟器中的一个问题吗?

完整筹码:

*** Call stack at first throw:
(
    0   CoreFoundation                      0x012955a9 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x013e9313 objc_exception_throw + 44
    2   CoreFoundation                      0x012970bb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x01206966 ___forwarding___ + 966
    4   CoreFoundation                      0x01206522 _CF_forwarding_prep_0 + 50
    5   UIKit                               0x006a26ff -[UITableViewRowData(UITableViewRowDataPrivate) _updateNumSections] + 111
    6   UIKit                               0x006a23b0 -[UITableViewRowData invalidateAllSections] + 66
    7   UIKit                               0x00559d23 -[UITableView(_UITableViewPrivate) _updateRowData] + 113
    8   UIKit                               0x0055565c -[UITableView noteNumberOfRowsChanged] + 105
    9   UIKit                               0x00562708 -[UITableView reloadData] + 773
    10  Foundation                          0x00c6e94e __NSThreadPerformPerform + 251
    11  CoreFoundation                      0x012768ff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
    12  CoreFoundation                      0x011d488b __CFRunLoopDoSources0 + 571
    13  CoreFoundation                      0x011d3d86 __CFRunLoopRun + 470
    14  CoreFoundation                      0x011d3840 CFRunLoopRunSpecific + 208
    15  CoreFoundation                      0x011d3761 CFRunLoopRunInMode + 97
    16  GraphicsServices                    0x01d3e1c4 GSEventRunModal + 217
    17  GraphicsServices                    0x01d3e289 GSEventRun + 115
    18  UIKit                               0x004f5c93 UIApplicationMain + 1160
    19  iPanopto                            0x000020f9 main + 121
    20  iPanopto                            0x00002075 start + 53
)

2 个答案:

答案 0 :(得分:1)

当UITableViewController没有正确连接到NIB中时,我遇到了这个问题...或者在NIB文件中没有定义特定的自定义单元类。

答案 1 :(得分:0)

由于ARC,您的UITableView的父视图可能会在幕后发布。我也曾遇到过这个问题,并最终通过this回答设置在正确的轨道上(感谢托马斯!)。请注意,此问题的根源可能存在于实际表所在的“上游”相当高的位置。