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

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.

Related

How to load a xib file from a storyboard?

I am new to iOS programming and I am working on a project which will use both XIB files and storyboard.
I have two modules in it basically. First module is made from XIB files which also runs independently. I have made another module using storyboard and I had to integrate these two independently running modules. The screen of my first module which I want to connect to my storyboard is a subclass of UIViewController and I was able to do that with the help of stackoverflow (How to load a storyboard from a XIB file?) by creating an object of UIStoryBoard. Now my application is able to go to the storyboard but I can't come back to my first module which is made up of XIB files.
Please let me know how can I connect to the same instance of the last screen of the first module through which storyboard is called so that I can move back and forth through these views easily. Connecting to the same instance of the XIB file is important because it is a chat screen and when I come back to this screen, I would like to get back to the chat where I had left it and also when I come back to the storyboard (by clicking a button on the chat screen) I have a slider on the screen which should display the value which the user must have chosen when they were on this screen last time. I guess creating a new object should give me a new screen which won't work in this situation. This kind of mechanism works well within storyboard with the use of segue where we can define both source and destination view controller.
Please help me achieve the same in my situation.
Please also check the screen shots of the XIB file and the storyboard which I want connected.
Thanks.
Convert the nib files into storyboard, it will help you easier to manage your application.
Well in your case, what i see is from nibs is that there is a navigation controller in storyboard and also there will be a root view controller navigation controller from xib files.
Well the navigation controller stack has all VCs you pushed into and you can get back it in different ways.

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

Iphone using mainwindow.xib confusion

In a navigation based application, when I want to create and use other uiviews and uitableviews I need to create their controller and views. in an example I saw that I can simply create a new controller with .xib file, design it, and just call that xib file from my navigationcontroller.
In another example, some stuff was going on also in the mainwindow.xib and some new controllers and navigation items were added from the mainwindow.xib.
What is the difference between these methods? when and why I should need to open and edit the mainwindow.xib file to add a controller?
The mainwindow.xib is your UIWindow component which you can see as a representation of your iphone screen, it will always be there no matter what. In your examples when you are showing your view controller dirrctly that is because the controller is already a subview of your UIWindow which is the mainwindow.xib in the Interface Builder.
There really is no difference between the 2 methods, in the first one you are adding your controller as a subview progrmatically using:
[window addsubview:mynavcontroller]
And in the second one youbare doing it thru interface builder, you may use whichever method you feel more comfortable with.
You do not really need a controller to show a view, however they can be handy if you want to do any extra stuff such as rotating your view or loading certain data when the view is loading. That being said you could add your view as a subview of your window and it would still work.

iPhone Dev: Tab View controller. Buttons on first view don't show actions in File's Owner

Hey all, I'm really new to iphone development and am getting really frustrated. I know ASP and Javascript and i'm trying to do this objective-c. I took a course on lynda and now i'm trying to hook up a tab view.
I placed buttons on the first view of the tab view controller. I then went into the header file and created the - (IBAction) for the 4 buttons on there and added the function in the implementation file. The problem is when i go back to Interface builder and try to connect the actions to the buttons, they don't show up. I have no actions listed in the File's owner so i can't do anything. Can anyone out there please help! thanks.
damien
You're doing it backwards (IMHO). create the Actions and Outlets (don't forget to save the source), then create the items in IB (note that you have to refresh IB so that it can re-read the source.
In tab view controller app make sure that class of view is your ViewController class and also in MainWindow.xib make sure all tabs are referencing respective ViewController

iPhone navigation controller basic question

This is a basic question about navigation controller, however, I don't seem to get it right.
I am creating a basic navigation controller application and using my custom view instead of the default rootviewcontroller and rootviewcontroller.xib that are automatically generated.
Here is what I have done:
Opened the MainView.xib and deleted the rootviewcontroller
Then, Xcode->new file->UIViewController class (with xib) and named it test
Opened mainview.xib, clicked on the section where it was pointing to rootviewcontroller and in inspector, changed the xib to test
In test, I just added a button.
However, when I load the application, the test doesn't seem to load. I added a log statement for viewdidload just to verify and the statement is never logged. Please let me know the fundamental connection I am missing here.
You must change the class of the RootViewController to your own (Inspector -> CMD+4).