The row value is always 0 in tableViewSelectionDidChange


I set a breakpoint in my tableViewSelectionDidChange event, and the row value is always 0.

Why is that? The speakers voice is always Agnes.

[code]- (void)tableViewSelectionDidChange:(NSNotification *)notification
NSInteger row = [_tableView selectedRow];
if(row == -1) {
NSString *selectedVoice = [_voices objectAtIndex: row];
[_speechSynth setVoice: selectedVoice];
NSLog(@“new voice selected = %@”, selectedVoice);


What could the issue be?


First, check to see if the _tableView is nil.

- (void)tableViewSelectionDidChange:(NSNotification *)notification
    NSLog ("%s: %@", __PRETTY_FUNCTION__, _tableView);

If the _tableView is nil, the row value will always be zero.


I think you found the issue, but how can the tableview be null when it has the list of voices in it? Meaning the datasource is wired up correctly, and so is the delegate since my tableViewSelectionDidChange is getting called.

I changed the log message a bit too:

and I see this in my logs:

2013-05-12 08:39:36.193 SpeakerLine[65033:303] init... 2013-05-12 08:39:38.044 SpeakerLine[65033:303] is tableview null -[SLAppDelegate tableViewSelectionDidChange:]: _tableView (null) 2013-05-12 08:39:38.045 SpeakerLine[65033:303] new voice selected = 2013-05-12 08:39:42.801 SpeakerLine[65033:303] is tableview null -[SLAppDelegate tableViewSelectionDidChange:]: _tableView (null) 2013-05-12 08:39:42.802 SpeakerLine[65033:303] new voice selected =

So it looks like it is null, but I’m lost as to how it could be null?


Did you check the connection of _tableView to the NSTableView instance in the nib file?


Thanks that worked, not sure if that was in the instructions though!