开发者

iPhone: create new "View-based Application" = no view controller?

开发者 https://www.devze.com 2023-01-03 21:51 出处:网络
I have created a new iPhone \"View-based Application\" in Xcode. I then added a new \"UIViewController subclass\" and checked the \"with XIB for user interface. Now the issue I have is that after hook

I have created a new iPhone "View-based Application" in Xcode. I then added a new "UIViewController subclass" and checked the "with XIB for user interface. Now the issue I have is that after hooking up all the variables and message handlers, I cannot push the new controller onto the stack using the following code:

[self.navigationController pushViewController:self.cabinetController
                                     an开发者_如何学JAVAimated:YES];

All the variables and views are hooked up correctly, so all that I can think of is that its the way I am doing it, by pushing it onto the "navigationController". Is there something I am missing here? (I am very new to iPhone and Apple programming in general, so its probably a very simple oversight).

I realise that not enough information has been supplied ... here is a link to the project. Please note that it is an educational exercise has some creatively names classes.

http://files.me.com/nippysaurus/4yqz8t


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;
}


You need to change your view controller to a navigation controller, with its root view controller set as the current view controller.


If you examine your self.navigationController, you will realize it is nil. Messaging nil doesn't hurt, so no error message here.

Add another layer with a UINavigationController, and add your RandomShitViewController (nice name btw.) as its root view controller.

The navigation controller handles the push / pop part, your old controller manages its view.

0

精彩评论

暂无评论...
验证码 换一张
取 消