In my document based OS X app, I have an empty NSScrollView in the xib, with "show vertical scroller" set. At run time I generate a view with buttons for navigation, which I set as the document view for the NSScrollView. Most of the time, this works well, but about 25% of the time, seemingly at random (or at least I can't reproduce any particular condition yet!), instead of a scroller on the side, I get a black bar where the scroller should be. If I resize the window, the black bar disappears, the scroller appears and works fine.
The result is that if I open six or seven blank documents, one after the other, about 3 of them will not have immediately functioning scrollviews.
Here is the code that creates the view with the navigation buttons, and adds it as the NSScrollview's documentView.
YMScrollDocView is a subclass of NSView that sets isFlipped to YES. navScrollView is the outlet to the scrollview in xib.
float allHeight = 0.f; // Consider starting from the top
//float xOffset = 2.f; // Offset addjustments
float spacing = 4.f; // Spacing
float buttonCellHeight = 40.f;
YMScrollDocView *navView = [[YMScrollDocView alloc]init];
//1
NSButton *overviewButton = [[NSButton alloc]initWithFrame:NSMakeRect(0, allHeight, self.navScrollView.bounds.size.width, buttonCellHeight)];
[overviewButton setTitle:@"Overview"];
[overviewButton setButtonType:NSMomentaryLight];
[overviewButton setBordered:NO];
[[overviewButton cell]setBackgroundColor:[self colorWithHexColorString:@"30BDF8"]];
[overviewButton setBezelStyle:NSRegularSquareBezelStyle];
[overviewButton setButtonType:NSCellIsBordered];
[overviewButton setTarget:self];
[overviewButton setAction:@selector(goToOverview)];
[overviewButton setRefusesFirstResponder:YES];
[navView addSubview:overviewButton];
allHeight += buttonCellHeight;
allHeight += spacing;
//2
NSButton *curriculumButton = [[NSButton alloc]initWithFrame:NSMakeRect(0, allHeight, self.navScrollView.bounds.size.width, buttonCellHeight)];
[curriculumButton setTitle:@"Curriculum"];
[curriculumButton setButtonType:NSMomentaryLight];
[curriculumButton setBordered:NO];
[[curriculumButton cell]setBackgroundColor:[self colorWithHexColorString:@"36FBF8"]];
[curriculumButton setBezelStyle:NSRegularSquareBezelStyle];
[curriculumButton setButtonType:NSCellIsBordered];
[curriculumButton setTarget:self];
[curriculumButton setAction:@selector(goToCurriculum)];
[curriculumButton setRefusesFirstResponder:YES];
[navView addSubview:curriculumButton];
allHeight += buttonCellHeight;
allHeight += spacing;
(I add more buttons with repetitive code here, then finish with the following code.)
[navView setFrame:NSMakeRect(1, 1, self.navScrollView.bounds.size.width, allHeight)];
[[self navScrollView]setDocumentView:navView];