The row value is always 0 in tableViewSelectionDidChange


#1

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) {
return;
}
NSString *selectedVoice = [_voices objectAtIndex: row];
[_speechSynth setVoice: selectedVoice];
NSLog(@“new voice selected = %@”, selectedVoice);

}[/code]

What could the issue be?


#2

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.


#3

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 = com.apple.speech.synthesis.voice.Agnes 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 = com.apple.speech.synthesis.voice.Agnes

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


#4

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


#5

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