Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tableview - unrecognized selector didSelectRowAtIndexPath

I have been having an issue with my app crashing on selecting something in the tableView. This is not 100% reproducible, but it happens relatively often.

What happens is inside my EventListViewController class (a subclass of UITableViewController), I overwrite the didSelectRowAtIndexPath function because I am using a search bar in this class as well, and I want it to only select when you are not searching.

The code looks like this:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(!searching)
        [super tableView:tableView didSelectRowAtIndexPath:indexPath];
}

However, when it crashes, I break on exception and this is the message I get, on the line that calls the super function:

[EventListViewController tableView:didSelectRowAtIndexPath:]: unrecognized selector sent to instance 0xa648e50

I printed out some stuff on the debugger and it all looks fine to me:

(lldb) po 0xa648e50
(int) $1 = 174362192 <EventListViewController: 0xa648e50>

(lldb) po self
(EventListViewController *) $2 = 0x0a648e50 <EventListViewController: 0xa648e50>

(lldb) po tableView
(UITableView *) $3 = 0x070fd400 <UITableView: 0x70fd400; frame = (0 0; 320 367); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x6e46750>; contentOffset: {-0, -0}>

(lldb) po indexPath
(NSIndexPath *) $4 = 0x06e8caf0 <NSIndexPath 0x6e8caf0> 2 indexes [1, 1]

(The tableView has 2 sections,and the second section has 2 entries)

Anyone have any Idea what is happening? let me know if you need any more information.

Note: after more investigation I have found that this is 100 % reproducible with the following steps: 1: load the app, and click on either of the two entries. 2: Go back to the tableView controller 3: tap BELOW both of the entries, in the white space where there shouldn't be a cell The app will crash, but notice that the indexPath doesn't say its trying to select a cell that is outside the bounds of the tableView, just that the tableView didSelectRowAtIndexPath method doesn't exist

like image 268
TheWiseOne Avatar asked Aug 05 '12 22:08

TheWiseOne


1 Answers

The call to super in tableView:didSelectRowAtIndexPath: is unnecessary. If I remember correctly, UITableViewController does not provide a default implementation of that method. Thus, your call to super results in a crash.

like image 56
Dave DeLong Avatar answered Oct 17 '22 00:10

Dave DeLong