How to edit the MainWindow.xib (to change the default view it loads) - iphone

Hi I am trying to change the default view MainWindow.xib loads. I am using view based app. I changed the app delegate file, added my new view as a subview to the main window. but in interface builder it still says mainwindow.xib loads from the default view not my newly added view. (BTW I added a new xib file for my new view and that is the one I want to load at startup.)
thanks.

If you want to change from using MyAppViewController.xib to `MyOtherView.xib', you also need to change the class of the view controller in Interface Builder. You can do this by selecting the view controller, going to the Identity tab (the last one) and putting the class name of your new view controller in the "Class" field.

Change the 'Main nib file base name' in the Info.plist of your App too if you have another Main.XIB.

Related

View controller suddenly wont connect to .h file

I created a new View Controller, I then opened up and created a new filed (Objective-C class) and then created a subclass of UIVewcontroller. I added my table views and labels in story board and now suddenly it wont connect them to the .h subclass Ive created. Any suggestions?
You have to name that the view controller is part of your class. Select your view controller and on the third tab on the right write the name of your view controller. Here is a picture I got from this tutorial to help:

Can't load view from an external xib?

The project i'm using is the sample code named "Tabster" provided by Apple.
I can load a view from a external xib by this:
In MainWindow.xib, drag a view controller to the tab bar controller.
File -> New -> File, add a new class named "NewTabItemA", subclass of UIViewController, with "With XIB for User Interface." selected.
In MainWindow.xib, change the Class of the new view controller to "NewTabItemA" in Identity Inspector and change the NIB Name to "NewTabItemA" in Attributes Inspector.
I can NOT load a view from a external xib while only the second step is different.
In MainWindow.xib, drag a view controller to the tab bar controller.
File -> New -> File, add a new class named "NewTabItemB", subclass of UIViewController, leave "With XIB for User Interface." unselected.
File -> New -> File, add a new xib file from the "View" template, name it as "NewTabItemB".
In NewTabItemB.xib, change the file owner to "NewTabItemB".
Control drag the file owner to the View, set it as the file owner's outlet.
In MainWindow.xib, change the Class of the new view controller to "NewTabItemB" in Identity Inspector and change the NIB Name to "NewTabItemB" in Attributes Inspector.
What did i miss?
Thank you all in advance.
Have you tried to change identifier of the xib? In interface builder click on window and set it in the properties. (3d tab)

viewDidLoad nor init are being called at application start iphone

This is a novice error for sure. In Xcode 4 i have created a Window Based application in which i put a TabBarController as the root controller. When the application starts, the first tab of the tabbar is selected and thus the view corresponding to that tab is shown. The problem is that the View Controller that corresponds to that view in the first tab is not being read, i put some logs in the init, viewWillLoad, and viewDidLoad methods and none of them are being shown. I have linked the controllers correctly, plus Xcode links them automatic if you select that option when creating a new view controller. Here's how it looks like in my project.
This is how it looks like in the tab controller i have linked to the view.nib:
And this is the view, it is linked to the view controller:
And here's the View Connected to the File's Owner Outlet:
Everything looks fine for me so i don't understand why it's not calling those methods in the view controller when the application starts or when the tab corresponding to that view is being selected.
Thanks in advance for the help.
I fixed it. The problem was that the referencing class was UIViewController intead of the view controller i created for it. The answer was to go to MainWindow.xib then select View Controller - Home then go to Identity Inspector and select the View Controller i created for it in this case the HomeViewController.h

iOS: Cannot get view to display with Navigation Controller

I'm trying to display a controller loaded from a NIB in my navigation controller (iOS 4/Xcode 4), but it is not working. Interface Builder doesn't allow me to choose any of my nibs; when I try to manually type one I get this error:
warning: Unsupported Configuration: Navigation Controller NIB Name set to MyViewController.nib (This view controller is not intended to have its view set in this manner)
What's this all about? One thing to make note of: I manually added the Navigation Controller after creating a view-based project. I decided that I should use one after I had already created the project, instead of choosing Nav-based from the beginning. Perhaps I forgot a setting?
I think you're trying to set the NIB of the navigation controller itself.
This is not what you want to do: you instead want to set the nib of the root view controller of your navigation controller. To do this, you should expand the navigation controller via the navigation panel (the left hand panel with a list of all the objects in your current NIB).
Selected 'Root View Controller', and then set its NIB and class as appropriate.
The reason you're getting an error right now is you're actually trying to set the navigation controller's NIB, which XCode is quite rightly not letting you do.

How to change the default View Controller that is loaded when app launches?

I have an application, say 'MyApp', which by default loads the view controller 'MyAppViewController' whenever the application launches. Later, I added a new view controller 'NewViewControler' to the project.
I now want the 'NewViewController' to be my default view controller which loads when the app launches.
Please let me know what changes I need to make in my project to achieve this.
Its easy, just:
Open your Storyboard
Click on the View Controller corresponding to the view that you want to be the initial view
Open the Attributes Inspector
Select the "Is Initial View Controller" check box in the View Controller section
Open MainWindow.xib and replace MyAppViewController with NewViewController.
In your app delegate class, replace the property for MyAppViewController with one for NewViewController. Connect NewViewController to its new outlet in Interface Builder.
In application:didFinishLaunchingWithOptions: add NewViewController's view to the window instead of MyAppViewController's view.
Most likely your main NIB file is still set to "MainWindow", check your *-Info.plist file.
If that's the case you can open the MainWindow.xib in Interface Builder. You should see a View Controller item. Bring up the inspector window and change the Class Identity to point to your new class. That should take care of instantiating your class.
As this feels like a "newbie" question (please pardon me if I'm mistaken) I would also highly recommend the following article:
iPhone Programming Fundamentals: Understanding View Controllers
Helped me understand the whole ViewController thing and the IB interaction..
As for me with xcode 4.3.3, all I had to do was simply replace all references of 'MyAppViewController' with 'NewViewController' in the AppDelegate h and m files.
Perhaps all the other steps have been taken out in the newer versions of xcode.
Hope this helps.