title: XCode 4.2 click on button switch to another view
body: <p>In Xcode 4.2, I know that one can use the storyboard segue to have a push of a button to go to another view.</p>
  
  <p>But say i want to storyboard, but not using segue push, instead code my own button to display another view, how to do it?
  Must i include a navigation controller?</p>
  
  <p>EDIT: added source codes</p>
  
  <p>AppDelegate.h</p>
  
  <pre><code>//
  //  AppDelegate.h
  //  Sandbox1
  //
  //  Created on 6/29/12.
  //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
  //
  
  #import &lt;UIKit/UIKit.h&gt;
  #import "ViewController.h"
  
  @interface AppDelegate : UIResponder &lt;UIApplicationDelegate&gt;
  
  @property (strong, nonatomic) UIWindow *window;
  @property (strong, nonatomic) ViewController *viewController;
  @property (nonatomic, retain) UINavigationController *navController;
  
  @end
  </code></pre>
  
  <p>AppDelegate.m</p>
  
  <pre><code>//
  //  AppDelegate.m
  //  Sandbox1
  //
  //  Created on 6/29/12.
  //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
  //
  
  #import "AppDelegate.h"
  
  @implementation AppDelegate
  
  @synthesize window = _window;
  @synthesize viewController;
  @synthesize navController;
  
  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary     *)launchOptions
  {
      // Override point for customization after application launch.
  
      self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
      self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone"     bundle:nil];
      navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
      [self.window addSubview:[navController view]];
      [self.window makeKeyAndVisible];
  
      return YES;
  }
  
  - (void)applicationWillResignActive:(UIApplication *)application
  {
  }
  
  - (void)applicationDidEnterBackground:(UIApplication *)application
  {
  }
  
  - (void)applicationWillEnterForeground:(UIApplication *)application
  {
  }
  
  - (void)applicationDidBecomeActive:(UIApplication *)application
  {
  }
  
  - (void)applicationWillTerminate:(UIApplication *)application
  {
  }
  
  @end
  </code></pre>
  
  <p>ViewController.h</p>
  
  <pre><code>//
  //  ViewController.h
  //  Sandbox1
  //
  //  Created on 6/29/12.
  //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
  //
  
  #import &lt;UIKit/UIKit.h&gt;
  #import "CreateViewController.h"
  
  @interface ViewController : UIViewController {
      CreateViewController *createViewController;
  }
  
  - (IBAction)clickButton:(id)sender;
  
  @end
  </code></pre>
  
  <p>ViewController.m</p>
  
  <pre><code>//
  //  ViewController.m
  //  Sandbox1
  //
  //  Created on 6/29/12.
  //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
  //
  
  #import "ViewController.h"
  
  @implementation ViewController
  
  - (IBAction)clickButton:(id)sender{
      if(!createViewController){
          createViewController = [[CreateViewController alloc] initWithNibName:@"CreateViewController" bundle:nil];
      }
      UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
      self.navigationItem.backBarButtonItem = backBarButtonItem;
      [self.navigationController pushViewController:createViewController animated:YES];
  }
  
  - (void)didReceiveMemoryWarning
  {
      [super didReceiveMemoryWarning];
      // Release any cached data, images, etc that aren't in use.
  }
  
  #pragma mark - View lifecycle
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
  // Do any additional setup after loading the view, typically from a nib.
  }
  
  - (void)viewDidUnload
  {
      [super viewDidUnload];
      // Release any retained subviews of the main view.
      // e.g. self.myOutlet = nil;
  }
  
  - (void)viewWillAppear:(BOOL)animated
  {
      [super viewWillAppear:animated];
  }
  
  - (void)viewDidAppear:(BOOL)animated
  {
      [super viewDidAppear:animated];
  }
  
  - (void)viewWillDisappear:(BOOL)animated
  {
      [super viewWillDisappear:animated];
  }
  
  - (void)viewDidDisappear:(BOOL)animated
  {
      [super viewDidDisappear:animated];
  }
  
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  {
      // Return YES for supported orientations
      return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
  }
  
  @end
  </code></pre>
  
  <p>CreateViewController.h</p>
  
  <pre><code>//
  //  CreateViewController.h
  //  Sandbox1
  //
  //  Created bon 6/29/12.
  //  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
  //
  
  #import &lt;UIKit/UIKit.h&gt;
  
  @interface CreateViewController : UIViewController
  
  @end
  </code></pre>
  
  <p>CreateViewController.m</p>
  
  <pre><code>//
  //  CreateViewController.m
  //  Sandbox1
  //
  //
  
  #import "CreateViewController.h"
  
  @implementation CreateViewController
  
  - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  {
      self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
      if (self) {
          // Custom initialization
      }
      return self;
  }
  
  - (void)didReceiveMemoryWarning
  {
      // Releases the view if it doesn't have a superview.
      [super didReceiveMemoryWarning];
  
      // Release any cached data, images, etc that aren't in use.
  }
  
  #pragma mark - View lifecycle
  
  /*
  // Implement loadView to create a view hierarchy programmatically, without using a nib.
  - (void)loadView
  {
  }
  */
  
  /*
  // Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
  - (void)viewDidLoad
  {
      [super viewDidLoad];
  }
  */
  
  - (void)viewDidUnload
  {
      [super viewDidUnload];
      // Release any retained subviews of the main view.
      // e.g. self.myOutlet = nil;
  }
  
  - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  {
      // Return YES for supported orientations
      return (interfaceOrientation == UIInterfaceOrientationPortrait);
  }
  
  @end
  </code></pre>