How to create Resource only Bundle for iPhone - iphone

We are experimenting with delivering our nibs in language specific bundles. For a couple of different reasons this would help us out.
My questions are around setting up a resource only bundle.
When I add a new bundle in xcode through the “New Project - Framework & Library - Bundle” menu xcode will add a new xcodeproj file. Is this correct? I thought a bundle was just a directory with a .bundle extension.
If I want to only have nib files in my bundle do I still need an executable file and a info.plist file?
So far I have manually created a bundle directory and added nib files. I and can access it with
NSBundle bundleWithPath
Not sure if it's loaded correctly, but the bundleWithPath method does not return nil.
But when I try to open a nib file from the bundle I get the following error:
* Terminating app due to uncaught exception
'NSInternalInco nsistencyException', reason: 'Could not load NIB in
bundle: 'NSBundle
(not yet loaded)' with name 'Nib''
And I have added the bundle to "Copy Bundle Resources".
Thanks for any info. I'm sure I'm making this harder than it should be.
EDIT: I went back and for a test added the line below to look for the xib instead of the nib. It works for xib but not for nib. I think this means that that the xib maybe is not getting compiled.
[languageBundle pathForResource:#"TestNib" ofType:#"xib"];

No, this is not correct. You should add a new target to your current project instead of creating a new project.
You don't need an executable, but you will probably need an Info.plist for it to be a proper bundle (it might not be strictly necessary, but it won't hurt to have one).
Now, is there a reason you're putting your nib files in a bundle instead of in .lproj directories? Also, you'll need to show some of your actual code before we can offer further help.

Related

"This class is not key value coding-compliant for the key" error when changing project from storyboard to xib files

I had lots of progress in a project which started using both storyboards and xib files. Then I decided to change it all to xib files so that firmwares older than 5.0 could use them. I had some trouble doing that so I created a new project and began copying all of the code and content of the xib files. However, when I ran the project, the debugger gave me the error "This class is not key value coding-compliant for the key gameStarts"(name of an outlet). I already tried cleaning all targets from the DerivedData folder, resetting my iOS simulator, and checking in the connections inspector of the designated xib file for rare outlets, but nothing seems to work. I have searched for hours without success. Help would be appreciated.
It seems that the .xib file has a outlet reference to gameStarts, but in the controller file, there isn't a IBOutlet property gameStarts. The most easy way to check whether you have set it properly in xCode 4 is switching to the xib file, selected the file's owner, click on the triangle on the right of the class name. This should bring you to the class file. I met similar problems before, they were caused by the incorrect reference.
And also find the element which is connected to gameStarts in xib file, re-connect it to your controller. I guess you would have copied the interface from storyboard file.

NIB in bundle is missing with name MainWindow-iPad

I have a Tab bar application having 6 tabs. When I debug and runthe app, it crashes by giving following message in console :
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/priyachaturvedi/Library/Application Support/iPhone Simulator/4.2/Applications/7C5CE523-A843-443A-9B0B-BDF2336EA7D0/Aljex Mobile-iPad.app> (loaded)' with name 'MainWindow-iPad''
I have already searched out the answersin the following links
How to fix iPhone Simulator trying to launch a Nib that isn't there?
How are XIBs loaded for localized apps?
and
Could not load NIB in bundle
and many other but nothing worked for me.
any one have any idea why this is happening to me???
Thanks in advance !!!
Suppose you already checked filenames and so on. So I exclude hypothesis of filenames mismatch. Where might be a problem? You might by mistake excluded MainWindow-iPad.xib from being copied into your app during build (linking) time. How to check that?
Insure MainWindow-iPad.xib is in your project.
In project in section Products select your app and in context menu choose Show in Finder. In Finder in context menu choose Show Package Contents. Ensure your MainWindow-iPad.xib is there. If it isn't there, go to step 3. If MainWindow-iPad.xib is in package, double check file names, the problem seems to be in filenames mismatch.
If it isn't there find MainWindow-iPad.xib in your project, select it and ensure checkbox of your target in Inspector isn't deselected. You might did that by mistake. Check this checkbox and rebuild.
I have the same problem too. I realise that when you enter the name of the xib file, it has to be "MainWindow-ipad" without the xib extension in your app targ

Unknown class FirstViewController in Interface Builder file

When I run my application i got this
I see in my console this message "Unknown class FirstViewController in Interface Builder file."
I am running TabBar application.
How can I fix this?
It looks like you deleted FirstViewController.h & .m from project, but forgot to change view controller's class in nib file.
Go to project , targets , build phases , compile Sources and add the unknown class ..done.
Right click on Storyboard --> Open As --> Source Code
Find your unknown class name in the storyboard source file. It may be because you have accidentally assigned a custom class name for one of your UIView subclass'.
It is kinda hard to understand your comments, but I think you may have deleted the FirstViewController but forgot to change all the references to it. you may need to go to MainWindow.xib and look for all FirstViewController UI components and delete them
Sometimes it happens when you change target name for some reason, you have then to open storyboard as source file, then search for old target name, replace it with the new name, should work if it is the case, hope it helps.
This can also happen if you use the same package name for multiple projects (if you're being lazy with your provisioning). Go into your user directory, then go to Library/Application Support/iPhone Simulator/[your sdk version]/Applications and delete what's in there. You may also have to delete the app from the device. That will remove any accidental references to files from other projects, which can cause this error.
When you add multi project to Workspace. If you use the same Product Name in your's projects. It can conflict.
Rename Product Name in the projects have a same name.
... Hope this help ....
This happened to me just after Git merge and resolving few conflicts.
It had screwed up my XCode project.
I tried all over the StackOverflow. At first I thought my Custom class .m file hasn't been added to the Compile Sources class list. But it's one case, however even after adding it, it gave me same issue back.
How I resolved:
I kept a backup of my .xib file and its backing custom class .m and .h files.
Then clean the project and try to run the app via XCode (which might not work)
Then re-add the files back to the XCode project and it will work.
Cheers!
This can sometimes happen if you made changes to a VC i.e. deleted prototype cell(s) within a tableview.
If all else fails I find cleaning project and restarting Xcode gets things back on track.

Could not load nib in bundle on iPhone device

I'm trying to test an app I'm developing on my iPhone. To do that I changed the target from Simulator to Device on Xcode. The application is correctly uploaded to the device and it works. The main view is shown but if I try to open a secondary view, the application crashes.
On the iPhone log (I installed the iPhone configuration utility to see the console [is the only way to see the log from iPhone?]) I can see this error:
Could not load NIB in bundle
But, on the simulator it works fine. What's wrong? Any ideas?
I had the same problem and fixed it like so:
Open XCode Target
Click the "Build phases" tab
Click the "Copy bundle resources" section
Click the +
Add the missing Nib file
I've found that sometimes the device is case sensitive and the simulator is not.
What's the filename of your xib?
or
Try uninstalling the app from the simulator and installing it again - the simulator might have an old file left over from a previous run of the app - have you renamed / moved the xib at all during development?
I had a similar problem and was getting the same error. Turns out I was using the full name of the xib file in the attributes panel under "NIB Name:"
Don't use "SomeViewController.xib", just use "SomeViewController" without the ".xib" extension.
I had the same problem when invoking initWithNibName:#"MyViewController"
Changing the invocation to initWithNibName:NSStringFromClass([MyViewController class]) worked well
You can try these things:
Make sure case is correct
Use xib filename without the ".xib" extension
Remove any -(dash) or other special chars, use _(underscore)
Remove the xib file from the project and add back to the Xcode project
Check the build settings and make sure deployment is changed to currect SDK
In my case, the xib simply wasn't being copied into the bundle. Once I added the xib into the "Copy Bundle Resources" step for the application target, everything went fine.
I finally managed to solve that issue with these two steps:
In the view controller files inspector, remove any localization
(just for testing)
Ensure that you have checked the correct target membership
I don't know why it works on the simulator :(
For me, the problem was exactly what FreeAsInBeer said: the nib somehow was missing from the bundle, whereas it had been there before and worked properly in previous versions of the app.
To fix the problem, I did the following:
Select the project in the Project Navigator.
In the project settings select Build Phases.
Expand Copy Bundle Resources.
Scroll down (if necessary) and click on the + button.
In the dialog that appears, click on the Add Other... button.
Browse for the missing .XIB file in the file system.
Build and Run... the missing nib should appear when you run it.
This is just what worked for me when I got that message. Your mileage may vary, since circumstances are not always the same for everyone, but I hope this helps someone who runs into this issue.
-Evan
I ran into the same problem. In my case the nib name was "MyViewController.xib" and I renamed it to "MyView.xib". This got rid of the error.
I was also moving a project from XCode 3 to 4.2. Changing the Path type did not matter.
I had the same error message.
My problem, however was that my language settings on my phone were set on "English" and the Region on "United Kingdom". However, the file that could not be loaded was placed in the de.lproj directory.
Moving the file into the root directory solved it.
A simple mistake that might cause this error is trying to initWithNibName on an imported viewController when you are using a storyboard rather than individual Nib files. If this is the case then just init the controller instead of trying to init with a nib that doesn't exist, or init those fields with nil.
If Storyboard and no nib, change initWithNibName: bundle: to just be init OR initWithNibName:nil bundle:nil
For what its worth, I received this error when one of my tab bar buttons had the wrong class assigned to it.
I've got it to run with delete all of the localization from the xib
In the right window.
Maybe the file is in the localization folder.
I've the same problem. And my solution is remove all Localizations for the view.
I had exactly the behavior you described: works on simulator but get the "Could not load NIB in bundle" when running on the device, and the app remain stuck on the launch image.
In my case the problem was about the MainWindow.xib file that Xcode automatically created with English localization. I am supporting English and Italian in my app and realized that I was missing the localized version of MainWindow.xib for the Italian language.
Because I had no need to localize this file (it's Xcode default to create it localized) I fixed the problem by simply removing the English localization, so the same file is used independently of the localization. Another way to fix the problem would be to add the missing localized version, if you need it.
The app was crashing on the device because my device is configured for Italian language. The simulator instead was set to English and this is why the app run correctly. Just to verify, I set the simulator to Italian language and the app crashed confirming the localization problem.
I also had this problem when I loaded a child view controller from initWithCoder, which is a good place to initialise, but keep in mind you have to add it as an actual child AFTER the view has loaded.
So shift something like this:
[self addChildViewController: self.pageViewController];
[self.view addSubview: self.pageViewController.view];
[self.pageViewController didMoveToParentViewController:self];
...out of your init method and into viewDidLoad. Not saying this is your problem in particular but this may be helpful to others.

Error running google tool kit for mac unit test

I am trying to install google toolkit for mac, everything is setup as advised here : http://code.google.com/p/google-toolbox-for-mac/wiki/iPhoneUnitTesting
but when I try to compile I get this error
Terminating app due to uncaught
exception
‘NSInternalInconsistencyException’,
reason: ‘Could not load NIB in bundle:
‘NSBundle (loaded)’ with name
‘MainWindow’‘
Any suggestions..? what am I missing...?
*EDIT : * Solution is to add your .xib file to the unit test target you have.
Alternative solution is to modify your unit testing target to not try and load the MainWindow nib:
Open your unit testing Target's info page
Switch to Properties tab
clear the contents of the "Main Nib File" textbox (it will probably have "MainWindow" before you clear it).
You mean when you run, not when you compile?
Are you sure you've created the proper type of application? The MainWindow.xib file is created by Xcode when creating a new project.
Delete MainWindow.xib from the project-info.plist file.