Problem Loading Initial Nib in iPhone Program - iphone

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.

Related

Tabbar controller with navigation controller in a single application

I have created an empty application and then added a window to it(made a window based application).
Then i added tabbarcontroller to it and navigation controller inside the tabbarcontroller. I have added nib files to my application for each tabs and given the nib names to viewcontrollers.Then i added a button to one of the nib file ,then application is crashing and giving error like -
Terminating app due to uncaught exception 'NSUnknownKeyException',
reason: '[ setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key btnNext.'
-----i have connected the iboutlet of buttons too.then why this error?
This error happens when the IBOutlets are not wired correctly. One common example is if you were to wire an IBOutlet in Interface Builder, but then delete the corresponding property in the corresponding class (where the IBOutlet was defined). Obviousily that's a mistake when that happens, but unfortunately Xcode will not give you a compile time error, and instead gives you this vague runtime error. Take a look at ALL IBOutlets in the relevant Interface Builder files and make sure they match up correctly to the IBOutlets in the header files (both in type and presence).
What you need is to add navigation controller to tab and inside the navigation controller in (view controller) you need to put the class name of view controller. Hope this link will also help you.

iPhone app crashes when I change "Main Interface"

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*?

Connecting outlets in Window Based App, Objective-C

I'm reading through a beginners iPhone text book and just finished writing all the code for a route tracker app that uses Map Kit and Core Location. I have the app running with no errors on my iphone 4 device but when I tried interacting I realized that none of my IBOutlets were connected to anything. When I referenced the beginning of the tutorial in the text, all it says is to "connect the appropriate outlets".
Here's why this usually simple task has me confused. The tutorial says to create a Window Based Project, so there is no ViewController. Then, in Interface Builder, the view is built in MainWindow.xib. The only IBOutlets of the project are located in Controller.h / Controller.m files that you create and which contain mostly all of the code for the app.
I usually ctrl-drag from File's Owner to the UI in Interface Builder, but in this project there seems to be no way for me to access the IBOutlets in Controller.h / .m from the MainWindow.xib file.
I'm frustrated because it seems like this should be such an easy fix but I'm totally stumped.. any help is really appreciated. Thanks
As I see it, you have two choices:
Add the outlets to the app delegate. This is probably not the best plan.
Put an instance of your controller class in the .xib file.
I think option 2 is what you want. If you check the Controllers section of the library, you'll see a component called "Object". Drag one of those into your xib, then inspect it. Select the info pane in the inspector (the circle with a white i in it) and change the Class to the name of your controller class.

App crashes when tab bar item is selected

I have a tab bar item with a UIScrollView and all the code works.
I link the UIScrollView IBOutlet in IB to a UIScrollView I placed in my View.
When I run the app and select the tab bar item I get the following error.
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key scrollView.'
I have no idea what this is. When I disconnect the ScrollView IBOutlet, then there is no crash.
Thanks
You probably renamed the name of the scrollView in the code without re-connecting the outlet in Interface Builder. Double check your code to make sure the spelling is the same as in Interface Builder, and for good measure, reconnect the outlet to scrollView.
Referring to this Apple forum thread, UITabBarController has multiple UIViewControllers each of which has its own nib file assigned to it. It's up to you to make sure you change the UIViewController's class file: in the nib file for each view controller and in the tab bar controller's nib file, you also have to do the same thing by changing each view controller's nib file and class.
So all in all you have to update settings in two places: the individual nib files for the view controllers and the tab bar controller's nib file. Think of it as creating the connections/bridges between the individual nib files and the tab bar controller.
Once these connections are made, your program should have no problem accessing your scrollView outlet, since that is how it ultimately accesses it: by using key-value coding by means of your tab bar controller (at least, that's my understanding). As of now it can't because the tab bar controller is not connected properly.

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