scrollRowToVisible not working


On page 106 at the bottom is a section on making the default voice get selected and making the scrollview of the table scroll to it if necessary, but it doesn’t work for me. I’m using Xcode 4.1 on a macbook pro with Lion. I’ve googled but can’t find anything about this not working. Any ideas? My awakeFromNib code is here:

- (void)awakeFromNib { NSLog(@"In awakeFromNib"); NSString *defaultVoice = [NSSpeechSynthesizer defaultVoice]; NSUInteger defaultRow = [voiceList indexOfObject:defaultVoice]; [tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:defaultRow] byExtendingSelection:NO]; [tableView scrollRowToVisible:defaultRow]; }

Note that I have changed the line:


as the former was giving a compiler warning.

I’m guessing that somehow the table View is not connected at the point this code is called as if I paste this code into the tableViewSelectionDidChange method then after selecting another voice, the default voice is selected and correctly scrolled to. I do have the tableView connected to AppController in the NIB.


I found the answer. It’s Lion that’s doing this with its new feature of restoring apps to their previous state. The Window of the app has a check box in the Attributes Inspector called “restorable”. Uncheck this and it all works as expected. I found this after spotting also that my initialFirstResponder for the window wasn’t working either, it was always remembering the last view that had focus when I closed the application rather than obey the initialFirstResponder binding. After unchecking the “restorable” check box both the table view scroll to default and first responder focussing work on application start.

A slightly annoying new feature from Apple there.