IOS: reemplazando la vista inicial en 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 (MainWindow.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?

preguntado el 27 de agosto de 11 a las 21:08

1 Respuestas

  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.

Respondido 28 ago 11, 02:08

Thanks - a sigabort had recently answered question 1! For future reference, I added a ViewController from the object library in to the main nib, and connected it to the relevant nib using the property inspector. From there it was just a question of connecting the app delegate object to the new nib by dragging and attaching. - Jack BeNimble

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.