1
votes

I am confused about how to implement a NSScrollView in the most basic way, so I will describe exactly what I do and hope that it is just to late for me to find my error:

  1. Create Xcode project.
  2. Adding a NSScrollView into MainMenu.xib.
  3. Creating new class inherited from NSView with the drawing method:

    (void)drawRect:(NSRect)dirtyRect
    {
    [super drawRect:dirtyRect];
    [[NSColor redColor] set];
    NSRectFill(dirtyRect);
    }
    
  4. Define the view of the NSScrollView to be that new class.

I expected to see a NSScrollView with a red background. Instead, I see the scroll view with no modification.

1
Show us your setup in IB.DrummerB
How? As a screenshot?DaPhil
Set the size of the view as I'm pretty sure you cannot rely on the scrollview to resize the content view (it's the other-way-round; the view is a certain size and the scrollview will accommodate it with scrollers on either/both axis). So do self.frame = NSMakeRect(0.0, 0.0, 400, 400); or something in the view's awakeFromNib.trojanfoe
How do you put the view in the scroll view? In IB, or by code?DrummerB
Ok, I just found that it works perfectly when auto layout is turned off! Why is that? Is there a way of using auto layout and still use this simple approach to have a scroll view?DaPhil

1 Answers

1
votes

The problem is auto layout. Turn it off and it will work fine.