tags:

views:

37

answers:

1

hi, how can I push a new view onto the stack of a NavigationController from a UIScrollView?

I tried

[self.navigationController pushViewController:myNewViewController animated:YES];

but get "navigationController not in structure or union".

regards

+1  A: 

You don't have a navigation controller in your app. You need to create one. Something like:

In your appDelegate create a UINavigationController instance variable and then use your existing viewController as the rootViewController of the navigation controller.

e.g. in pure code using a UITableViewController (you can use xibs as well which your template app probably does).

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

  // Create root view and navigation controller
  UITableViewController *rootViewController = [[[UITableViewController alloc] initWithStyle:UITableViewStyleGrouped] autorelease];
  self.navigationController = [[[UINavigationController alloc] initWithRootViewController:rootViewController] autorelease];

  // Not necessary if you're using xibs
  self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

  // Add the nav controller's root view to the window
  [window addSubview:navigationController.view];
  [window makeKeyAndVisible];

  return YES;
}

Then you can push/pop new views in the way you're attempting.

Ryan Booker
Thanks Ryan, the missing link was - yet again - not thinking about the obvious ... setting an IBOutlet to conect the navigation controller.
iFloh
Ah. That'll do it. :)
Ryan Booker