Search code examples
cocoacore-datanstableview

Exception when deselecting NSTableView row


I'm a bit lost with this... It seems I can't find why I can't deselect rows from my NSTableView. I allowed empty selection in Interface Builder but as soon as I call deselectRow: or deselectedAll:, I get an exception.

For example, with this code:

NSLog(@"Currently selected row index: %ld", [self.tableView selectedRow]);
[self.tableView deselectRow:[self.tableView selectedRow]];

I get:

2011-09-05 MyApp[18939:707] Currently selected row index: 1
2011-09-05 MyApp[18939:707] *** -[__NSArrayM objectAtIndex:]: index 18446744073709551615 beyond bounds [0 .. 3]

I even get the same kind of error if I call deselectRow: with a hard coded value (say 0) for testing. So I suppose the error originates from the binding with my NSArrayController or something?


Solution

  • A very long integer like that usually means a memory address is being translated into an integer. That in turn is usually caused by passing an object to a scalar variable.

    In IB, look at the selected object bindings for the interface elements. At some point, you handing an object to off to deselectRow instead of a scalar integer.