title: objective-c: add view to window on button click
body: <p>I'm new to objective-c so bear with me. This seems pretty simple but I must be doing something wrong. In IB I created an object, called it AppController and then added an action titled makeView and two IBOutlets, btnMakeView and mainWin, then connected everything properly and wrote the class file from that. </p>
  
  <p>In AppController.h I have this code: </p>
  
  <pre><code>#import &lt;Cocoa/Cocoa.h&gt;
  @interface AppController : NSObject {
      IBOutlet NSWindow * mainWin;
      IBOutlet id btnMakeView;
  }
  - (IBAction)makeView:(id)sender;
  @end
  </code></pre>
  
  <p>in AppController.m this code: </p>
  
  <pre><code>#import "AppController.h"
  #import "ViewController.h"
  @implementation AppController
  - (IBAction)makeView:(id)sender {
  
      //declare a new instance of viewcontroller, which inherits fromNSView, were going to allocate it with 
      //a frame and set the bounds of that frame using NSMakeRect and the floats we plug in.
      ViewController* testbox = [[ViewController alloc]initWithFrame:NSMakeRect(10.0, 10.0, 100.0, 20.0)];
  
      //this tells the window to add our subview testbox to it's contentview
      [[mainWin contentView]addSubview:testbox];
  }
  -(BOOL)isFlipped {
      return YES;
  }
  @end
  </code></pre>
  
  <p>in ViewController.h I have this code: </p>
  
  <pre><code>#import &lt;Cocoa/Cocoa.h&gt;
  @interface ViewController : NSView {
  }
  @end
  </code></pre>
  
  <p>and finally in ViewController.m I have this code: </p>
  
  <pre><code>#import "ViewController.h"
  
  @implementation ViewController    
  - (id)initWithFrame:(NSRect)frame {
      self = [super initWithFrame:frame];
      if (self) {
          // Initialization code here.
      }
      return self;
  }
  
  - (void)drawRect:(NSRect)rect {
      // Drawing code here.
  
      //sets the background color of the view object
      [[NSColor redColor]set];
  
      //fills the bounds of the view object with the background color
      NSRectFill([self bounds]);
  }
  
  @end
  </code></pre>
  
  <p>It compiles fine, there are no errors but  do not get an object, which I am assuming will be a rectangle, starting at x,y 10/10 and being 100x20. What am I doing wrong?</p>