iPhone app crashes when I change "Main Interface" - iphone

I have a navigation based iPhone app, and I want to load a view (MainMenu.xib) when the app is launched, instead of MainWindow.xib. If I change the target's "Main Interface", the app crashes when it is launched. How do I fix this?

You have to add the view you want to display on MainWindow.xib......in the IB of MainWindow.xib you have to change the name of the class as well as the nib name (give the name of the class)
After doing this make the object of the view in the Application delegate
In navigation based you also need to give the name of the class you want to display(this class is the class in which you had designed your table view)

adding this comment a few years after the problem first posted as can cause problems if you have Storyboards to manually change MAIN INTERFACE instead of choosing from drop down. If value in field is not a .storyboard file then xocde changes the plist setting to NIB based project and breaks the whole project.
See my comment here
What does "Main Interface" in Xcode actually *do*?

Related

Is setting the Main Interface in Xcode necessary for Apple acceptance?

My project is in Xcode 4.2, designed for iOS 4.2 and above.
I am not using a Storyboard so in the Summary, both Main Storyboard and Main Interface are blank.
Will this cause problems with my submission to Apple?
I ask because when I set the Main interface to my primary View Controller, I get this error when I compile: this class is not key value coding-compliant for the key mainTableView.'
and I don't know how to resolve it.
From the ViewController Programming Guide:
"If a main storyboard is declared in this file, then when your app launches, iOS performs the following steps:
It instantiates a window for you.
It loads the main storyboard and instantiates its initial view controller.
It assigns the new view controller to the window’s rootViewController property and then makes the window visible on the screen."
The key word being "if". Therefore I don't think it's necessary.
I have a universal app that started out as an ios3 app and was updated to universal in the past 6 months - I didn't declare any storyboard (I've not used storyboards at all yet) or Main Interface. I simply add my viewcontroller's view to the window in applicationDidFinishLaunching.
When you state that you "set the Main interface to my primary View Controller" did you mean you set the view (not the view controller)? Is this a Xib file? A View Controller won't work, it needs to be a View/Xib.

Absence of MainWindow.Xib in iOS 5

In iOS 5 sdk with Xcode4.2 i started creating an app with Empty Application Template.But in that template there is no MainWindow.xib.Some posts says to add a MainWindow manually.Is that the right way or proceeed the same without MainWindow.xib for a navigation Based application
The empty application template does not contain any other files - it's an empty template! If you want to create a navigation based application, you can do it in code by creating a navigation controller and setting it as the root view controller of the application window, or you can create your own xib file and set it to the "Main Interface" in your target summary settings.
For information, in XCode4.2/iOS5.0, Apple added the concept of story boards. Now by default, no MainWindow.xib file is created but MainStoryboard.storyboard. You can use it to develop your application. BUT, for backward compatibility, prefer add a nib file that you can name MainWindow.xib. I do not know any other way to use NIB files as it was done before XCode4.2

Problem Loading Initial Nib in iPhone Program

I'm having a problem similar to the one discussed in this thread, but the solution provided to him isn't working for me. I apologize for the lengthy description, but this is my first post on SO and I want to be complete.
I have a program that runs fine in the simulator. However, when I try to push it out to the device, I get an error that says this:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/mobile/Applications/....app> (loaded)' with name 'MainWindow''
So: it's trying to load a XIB called MainWindow, but it can't find it. That's because I don't have a XIB called MainWindow; the first XIB I load is called FrontPage.xib. I didn't start this program using one of the templates and thus was not provided with a MainWindow.xib file at the beginning.
The Google machine tells me that the Main nib file base name can be modified in my app's plist. So, I go there and I change it to FrontPage. Now, I get a different error:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0x12c270> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'
I'm pulling my hair out over here - anyone know a solution?
Make sure that your view is connected to your "View" outlet in Interface Builder. You do this by right clicking on your "File's Owner" in IB and then dragging to the "View" outlet to your View. Here's an illustration from a game I'm working on. Notice the blue line, dragged from the dot on the right to the "view".
Another thing you will want to check is your Info.plist. Make sure that you have called your nib file FrontPage and not *FrontPage****.nib***.
If Frontpage.xib is going to be your application's main xib, then you have to create a Window object and an App Delegate object in that xib in order for the app to be able to load. Before you can start presenting view controllers and such you have to configure the app and the window or it will crash as you describe. I would suggest creating a new project using a Window based template and just take a look at the MainWindow.xib that gets created automatically and try to mimic it in your Frontpage.xib..
.. Although I would just sincerely suggest using a MainWindow.sib in your project and making your Frontpage.xib a normal view controller xib. If you choose to add a new file to your project, then choose User Interface, then choose Application xib instead of View xib, then it will set you up with something close to what you need.
The project templates are important and useful. You should always use them. I start all of mine with a Window Based template. It is the most basic template and the most flexible.
If the view controller for FrontPage.xib is set properly by setting the File owner property via IB then you also need to set the view property. you can do this by control dragging from Fileowner to the view. From the error it appears that you have yet not set the view property for your view. Open the nib in Interface builder and and look for the View Connection in connection Inspector , this must be connected to file owner's view outlet. You don't need to declare it as a property anywhere.

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.

How to make a "view" Outlet show up in a ViewController nib?

I'm working on my first iPhone app and have been able to get most things done. There's one problem that I've run into a few times and I want to understand the issue better.
In XCode, if I go File->New File->UIViewController subclass and make sure that both UITableViewController subclass and With XIB for user interface are checked, then it creates a MyViewController.h, MyViewController.m, and MyViewController.xib.
When I look at this xib in Interface Builder, you can see that the File Owner has an Outlet called view that is already connected to the UITableView. No problem. This all makes sense and is great.
My issue comes when I've changed the type of my class (or done something else) and some how the "view" Outlet goes away. I get an error saying "view not showing up in file owner outlet".
My question is how do I then reconnect the UITableView as the "view" of the ViewController when the Outlet goes away? The only way I've been able to get it to work is to literally start over with a new xib/viewcontroller.
That "view" outlet should be coming from the parent class (in your case UITableViewController).
What do you mean by change type? If you are changing the name of your class, try using Edit > Refactor with the class name selected in Xcode.
In the "Document" window (cmnd + 0) - control + click on file's owner, a weird looking line thing will show up. drag the mouse over to your view and release. a little drop down will come up from which you can set the view to the File's Owner View outlet.
Typically the "view" outlet would be coming from the parent class (UITableViewController). If it's not showing up, then Interface Builder is not connected to your project than this could happen instead.
My problem was due to an edge case as described here: Interface Builder and Xcode integration not working