开发者

IOS - replacing the initial view in NavController

I'm trying to revise an app I did in iOS a few months ago that uses a navigation controller.

My goal is to replace the current default view controller with a new one (which will in turn call the original view controller)

In trying to tease apart what has to happen in order to do this. I've created a new view controller and the corresponding nib, and set them up as variables in the app delegate. In the app delegate, this is the current code which makes the call to the "old" initial view:

navController.viewControllers = [NSArray arrayWithObject:questionViewController];

[window addSubview:navController.view];

[self.window makeKeyAndVisible];

Question 1: the nib file for the main window (MainWin开发者_StackOverflow社区dow.xlb) has the question view controller as an object (as well as the navigation controller). Does it need to be there?

Question 2: what should I change to make the new view controller the default view?


  1. Yes, you need that connection otherwise you wouldn't be able to reference questionViewController from the app delegate like you currently are. But if the questionViewController is no longer your first view controller, you should replace it with a different one.
  2. Just like you already have, use
navController.viewControllers = [NSArray arrayWithObject:/*new first view controller*/];

Of course you'll also have to put it in the xib file and connect it to an IBOutlet so you can use it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜