Why isn't drawRect: getting called?
<p>I have an <code>NSView</code> subclass <code>foo</code> which overrides <code>drawRect</code>:</p>

<pre><code>- (void)drawRect:(NSRect)dirtyRect
{
    [self doStuff];
}
</code></pre>

<p>I would have expected that whenever I added an instance <code>bar</code> of my class as a subview of another view, <code>bar</code> would be redrawn. However, when I add <code>bar</code> as the <code>contentView</code> of the main window in my application, I'm not seeing this to be the case.</p>

<p>I tried adding another override:</p>

<pre><code>- (void)viewDidMoveToSuperview
{
    self.needsDisplay = YES;
}
</code></pre>

<p>...in hopes that when <code>bar</code> gained a superview, it would invalidate its display and force a redraw. No such luck (<code>viewDidMoveToSuperview</code> is being called, but not <code>drawRect:</code>).</p>

<p>I think I may be misunderstanding how <code>drawRect:</code> gets called, and I admit that I don't have the best understanding of the drawing event loop in general. I couldn't find a lot of documentation online about this.</p>

<p>So my question is two-fold: 1) What am I doing wrong in regards to getting <code>drawRect:</code> called? 2) Is there any relevant online documentation regarding the event loop which draws UI in cocoa?</p>

<p><strong>EDIT</strong>:</p>

<p>In my UI chain, the instance of <code>foo</code> which isn't getting <code>drawRect:</code> called on it has two subviews: one which is essentially a subclass of <code>NSTextView</code> which sizes to its content, and another which is an <code>NSScrollView</code>. By sheer force of luck, I happened to comment out the code which added the <code>NSScrollView</code>, and suddenly the instance of <code>foo</code> had <code>drawRect</code> called on it again.</p>

<p>So somehow my <code>NSScrollview</code> is keeping my <code>foo</code> from receiving <code>drawRect:</code> . From a quick Google search, I found that other people have had reported problems related to drawing and <code>NSScrollView</code>. However, most of those posts seemed related to subviews <em>within</em> <code>NSScrollView</code>, rather than superviews of <code>NSScrollView</code>.</p>

<p>So here's my newest question: what about my instance of <code>NSScrollView</code> is preventing its parent from receiving <code>drawRect:</code>?</p>