views:

967

answers:

6

This one is a doozy...

My buddy just downloaded the iPhone SDK on his Snow Leopard MacBook Pro. No matter what kind of project he creates (Window Based, View Based, etc...,) he can't create or use his own xib files. The project will compile and run fine until he adds a new xib file.

Here are some symptoms:

  • When he selects a pre-generated xib in Xcode (such as MainWindow.xib), no preview is shown on the right hand side. Double clicking on this file will open it in interface builder (This is correct behavior).
  • When he selects his own custom xib, the preview pane displays the XML content of the xib. Double clicking on his custom xib opens up the XML file in Xcode - as if it were a standard code file (This is jacked up).
  • Opening his custom xib from finder opens it in Interface Builder.
  • When building the application, the build warning says something to the effect of "Warning: No rule to process file /path/to/CustomXib of type sourcecode.xib for architecture i386"
  • At runtime he gets the error:

    Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] was unable to load a nib named "MyCustomXib"'

We've uninstalled Xcode from the command line and reinstalled. I've verified that it's the right version for his machine. I'm stumped!

A: 

Try changing the file type of the xib from "sourcecode.xib" to "file.xib". "sourcecode.xib" seems like it would try to treat the file as a source file, and not as the (default) xib file.

Dave DeLong
A: 

We have tried that and it did not work, thank you for the fast response!

Mike
I think you meant to post this as a comment on Dave DeLong's answer, not as an answer to your question. Please be careful—you need to use the “add comment” link to comment on an answer; the form at the bottom is only for answering the question.
Peter Hosey
A: 

The error...

Warning: No rule to process file /path/to/CustomXib of type sourcecode.xib for architecture i386"

... suggest the nib is for some reason in the "Compile Sources" build phase. Open the target and then open Compile Sources and see if the nib is listed there. If it is, move it to "Copy Bundle Resources" and try to compile again.

TechZen
xibs are supposed to be compiled. They compile to nib files.
Peter Hosey
Nevertheless, a .xib file should never show up in the "Compile Sources" phase of a target. If one did show up there, it would be reasonable to try and move it to its proper location to resolve this issue.
TechZen
If you ding people for sticking their necks out by making suggestion on weird problems, people will stop sticking their necks out. A simple comment that you don't think this is the source of the error would be sufficient in this case. This isn't the kind of problem in which any given answer if definitively wrong. In cases like this, wrong answers can nevertheless lead to a correct solution by triggering a realization or revealing information in testing the wrong answer.
TechZen
Huh… You're right. I thought I'd seen my xib files in Compile Sources, but they're in Copy Bundle Resources, even though Xcode compiles them. Sorry.
Peter Hosey
A: 

This is a total cop out, but after screwing around with Xcode, OS X, the terminal and seeing no progress, we've decided to wipe the machine and start fresh. The bug may be a consequence of upgrading directly from Tiger to Snow Leopard, and having some strange left-over settings.

Reed Olsen
A: 

It seems my xib- file was saved with wrong file info when created by File->New_file->Create an UIViewController subclass in XCode.

When I changed the file info into the same as for the MainWindow.xib, and also moved it from the Target compile folder, it worked fine; it both compiled and started in interface builder.

PS: I too upgraded directly from Tiger to Snow Leopard, so that could be a candidate for mixing the settings of Xcode?

Geir Haagensen
+1  A: 

Yes, I also had this problem and also upgraded directoy from Tiger to Snow Leopard. The fix for me was changing the file type of the nib file from sourcecode.xib to file.xib (control click on the nib file, select "Get Info", and modify the "File Type" in the dropdown.

Mark