Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simply embedding a custom NSView in an NSScrollView kills it

As soon as I embed my custom NSView in a scroll view, nothing is drawn in my custom view.

To replicate the issue, I created a vanilla Cocoa app. I subclassed NSView, and its drawRect handler, I do something simple like a red fillRect. I verify this works as expected:

- (void)drawRect:(NSRect)dirtyRect
{
    [super drawRect:dirtyRect];

    [[NSColor redColor] set];
    [NSBezierPath fillRect:dirtyRect];
    // Drawing code here.
}

Back to IB, I click on my custom view, then go menu Editor > Embed In > Scroll View.

There is no longer a red rectangle in my view. I've verified that my drawRect is no longer being called.

What gives?

I thought I'd come across a solution here, but it was of no help.

Seems so simple.

Running Xcode 5.0.2 & OS10.9.1.

like image 982
zzyzy Avatar asked Mar 20 '23 11:03

zzyzy


1 Answers

Fixed... I had to add something like this to my custom view:

- (NSSize)intrinsicContentSize
{
    return NSMakeSize(960,540);
}
like image 54
zzyzy Avatar answered May 21 '23 16:05

zzyzy