title: Why does my iOS app crash when trying presentModalViewController?
body: <p>I've been banging my head against this all day, it seems like something simple but I can't figure it out.</p>
  
  <p>I've got an iOS app that I created using the "View-based Application" template in XCode. Here is essentially the code I have:</p>
  
  <p>AppDelegate.h:</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  @interface AppDelegate : NSObject &lt;UIApplicationDelegate&gt; {
      UIWindow *window;
      MainViewController *viewController;
  }
  @property (nonatomic, retain) IBOutlet UIWindow *window;
  @property (nonatomic, retain) IBOutlet MainViewController *viewController;
  @end
  </code></pre>
  
  <p>AppDelegate.m:</p>
  
  <pre><code>#import "AppDelegate.h"
  #import "MainViewController.h"
  @implementation AppDelegate
  @synthesize window, viewController;
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
      [self.window addSubview:viewController.view];
      [self.window makeKeyAndVisible];
      return YES;
  }
  - (void)dealloc {
      [viewController release];
      [window release];
      [super dealloc];
  }
  @end
  </code></pre>
  
  <p>MainViewController.h:</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  @interface MainViewController : UIViewController {
  }
  -(IBAction) button:(id)sender;
  @end
  </code></pre>
  
  <p>MainViewController.m:</p>
  
  <pre><code>#import "MainViewController.h"
  #import "ModalViewController.h"
  @implementation MainViewController
  ...
  -(IBAction) button:(id)sender {
      ModalViewController *mvc = [[[ModalViewController alloc] initWithNibName:NSStringFromClass([ModalViewController class]) bundle:nil] autorelease];
      [self presentModalViewController:mvc animated:YES];
  }
  @end
  </code></pre>
  
  <p>There's nothing of interest in the ModalViewController.</p>
  
  <p>So the modal view should display when the button is pressed. When I press the button, it hangs for a second then crashes back to the home screen with no error message.</p>
  
  <p>I am stumped, please show me what I'm doing wrong!</p>