开发者

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 call开发者_如何学JAVAed 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".

Problem Loading Initial Nib in iPhone Program

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜