UITableViewCell unrecognized selector


I have a UITableView with a ViewController as its datasource and delegate. In the same XIB I have a custom cell for my search bar. The first cell in the table view is this cell. Sporadically, I'm getting a crash with the following exception:

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

Gdb shows that this is in fact my search cell and that it is a child of the tableview. Also, further inspection shows that the datasource is in fact correctly pointing to my view controller and not to the search bar cell. Based on this it seems that UIKit is simply sending the message to the wrong target. Anyone seen anything like this before? Could it just be a problem in the simulator?

Full stack:

*** 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
asked on Stack Overflow Dec 4, 2011 by George

2 Answers


I had this problem when the UITableViewController was not attached in the NIB correctly... or the specific custom cell class is not defined in the NIB file.

answered on Stack Overflow Dec 4, 2011 by craig1231

The parent view of your UITableView could be released behind the scenes due to ARC. I had this problem too once and was eventually set on the right track by this answer (thanks Thomas!). Note that the root of this problem may exist rather high 'upstream' from where the actual table lives.

answered on Stack Overflow Nov 29, 2013 by Jacob Oscarson • edited May 23, 2017 by Community

User contributions licensed under CC BY-SA 3.0