Fixing the scrollRowToVisible issue on 10.7/Lion


#1

As pointed out in this post for edition 3 of the book: http://forums.bignerdranch.com/viewtopic.php?f=12&t=2920, the scrollRowToVisible: method does not work correctly on 10.7 (Lion) with the default XCode settings. In order for the app to behave as described in the book, the NSWindow needs to have the “restorable” property deselected. Not being happy with only a GUI builder setting, I wanted to find the programatic way to resolve this. My solution was to call the setRestorable: method on the NSWindow within the awakeFromNib method of the AppDelegate:

- (void)awakeFromNib {
    if ([window_ respondsToSelector:@selector(setRestorable:)]) {
        [window_ setRestorable:NO];
    }
    NSString *defaultVoice = [NSSpeechSynthesizer defaultVoice];
    NSUInteger defaultRow = [voices_ indexOfObject:defaultVoice];
    NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:defaultRow];
    [tableView_ selectRowIndexes:indexSet byExtendingSelection:NO];
    [tableView_ scrollRowToVisible:defaultRow];
}

Is this the proper way to handle this programmatically or is there a more “correct” or reliable way of doing it? Is there any link that explains the issues or rationale behind “restorable” ignoring something like scrollRowToVisible:?


#2

I am guessing that the restoration of the window state happens AFTER awakeFromNib has been called… that’s why the state setting done in the example seems to be ignored. Its probably actually “overwritten”.


#3

My question goes with how to counter act this. On iOS we can do a check to see if the initial state has been loaded in viewDidAppear, but there doesn’t seem to be anything that equates to this on OSX.