0

My Mountain Lion app contains an NSScrollView with an NSTableView using an NSTableViewCell. I wanted the ScrollView to have rounded corners, like Reminders. I found an answer here that said to use:

[listScrollView setWantsLayer:YES];
[listScrollView.layer setCornerRadius:10.0f];

When I first start the app, everything works perfectly. I scroll down the list to view items at the bottom and quit the app. When I restart the app the top of the list is shifted down to match the top of the scroll bar, which remembers where I was scrolled to when I quit. However, scrolling or resizing the window causes the list to draw properly. If I click on one of the list items, it selects the item that should be at that position.

Here is the bottom of the list just before quit

Here is what is displayed after restarting the app

Greg Walters
  • 181
  • 5
  • Here is the original Question and Answer I found: http://stackoverflow.com/questions/5268467/how-can-i-get-nsscrollview-to-respect-a-clipping-path/9989911#9989911 – Greg Walters Aug 22 '12 at 21:40

1 Answers1

0

I figured out the problem, or at least how to avoid the strange behavior.

The strange behavior was in viewing a NSTableView's rows inside a NSScrollView after quitting a Cocoa app after partially scrolling down the TableView's items and then relaunching right away. Mountain Lion remembers the app's state of partially scrolled down and started drawing the TableView's rows at the top of the scroller knob, which was slid down from the top of the list.

The problem was where I was setting the ScrollView's layer to display, which I was using to create rounded corners for the scroll view.

I was originally setting the ScrollView's Layer in the Document's windowControllerDidLoadNib method using an IBOUTLET called listScrollView.

I moved that code into the ScrollView's drawRect method:

if (!self.wantsLayer) {
    [self setWantsLayer:YES];
    [self.layer setCornerRadius:10.0f];
}

Viola, the ScrollView now has rounded corners, which clip ScrollView's corners and scroller knob slot and the TableView's row corners at the top and bottom of the ScrollView.

Greg Walters
  • 181
  • 5