Could not load NIB in bundle - inspiration needed - iphone

I'm currently seeing this error:
MonoTouchException: Objective-C exception thrown. Name:
NSInternalInconsistencyException Reason: Could not load NIB in bundle:
'NSBundle </Users/imac/Library/Application Support/iPhone
Simulator/5.0/Applications/5D8B4B51-9FB2-4331-BFEB-B1A0AC77DF42/Tutorial.app>
(loaded)' with name 'MyFirstView'
I've looked through lots of other questions like:
NSInternalInconsistencyException Could not load nib in bundle
Could not load NIB in bundle
and lots of others
But I can't see that any apply here - they are mainly about file naming issues and my Nib does appear to be in the output package file with the correct name.
I'm using MonoTouch 5.2.5 and xcode 4.2, and targeting SDK5
Does anyone have any ideas about what I could try to fix this?

I have faced the same Problem today. I refactored (rename) viewController to myCustomViewController and got this error. When I searched in my project files, I saw that I have used self.viewController = [[[MyTableViewController alloc] initWithNibName:#"viewController" bundle:nil] autorelease];
NibName was changed but in #" " it was old name. so I changed it to
self.viewController = [[[MyTableViewController alloc] initWithNibName:#"MyTableViewController" bundle:nil] autorelease];
and error was removed. Do it and hope your error will be removed.
Vote up if it helps.

The problem eventually it seems was somewhere in the extended toolchain - somewhere between MonoDevelop, xCode4 and the simulator.
Restarting everything, and resetting the simulator cleared the problem.
Later in the same chain I've seen smaller issues with "old NIB file outlets" persisting on the simulator even after I've definitely deleted them and rebuilt - so something is still going wrong somewhere... but a clean solves it each time.

So I had a similar solution in MonoDevelop. I created an empty mono touch project. When I deleted the xib file associated with the auto created project, i ran into problems. Even though I created a new view and connected the outlet to that controller, I had to go back and recreate the xib file associated with the controller (with the same name) again, and then connect that original view and controller via the outlet

Related

Works on iOS Simulator but not on iPhone

The line of code works fine on the iOS Simulator 6.0, but is crashing when I try to run it on my iPhone, also running iOS6.
[menuView addSubview:mvc.view];
Why is this happening, and how can I fix it?
This is the more complete version of the code:
SDMenuViewController *mvc = [[SDMenuViewController alloc] init];
[menuView addSubview:mvc.view];
And this is what it is crashing with:
2012-10-08 21:32:32.423 CrunchCalculator1-2[21019:907] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </var/mobile/Applications/EDD23933-CE20-4AFD-A2B1-CDD56AD658E8/CrunchCalculator1-2.app> (loaded)' with name 'SDNestedTableView''
*** First throw call stack:
(0x39cd03e7 0x35ece963 0x39cd0307 0x39ee0fd1 0x39ee05ff 0x39dd9031 0x39e0786d 0x39d63419 0xb20d9 0x39d63541 0x39da3d29 0x39d9fac5 0x39de1199 0xb17c5 0x39da4a71 0x39da45f5 0x39d9c803 0x39d44ce7 0x39d44775 0x39d441b7 0x31e145f7 0x31e14227 0x39ca53e7 0x39ca538b 0x39ca420f 0x39c1723d 0x39c170c9 0x39d9b43d 0x39d98289 0xb1523 0x3792fb20)
libc++abi.dylib: terminate called throwing an exception
Thanks!
I'm not quite sure how it worked on your simulator (when I tried it on mine, I got the crash you list in your original question). Anyway, you can fix it by looking at the following items:
The main problem is that the NIB was not included in the bundle. Add it to the project target's "Copy Bundle Resources", e.g.:
While you're looking at your "Copy Bundle Resources", you'll also want to include SDSubCell.xib, SDGroupCell.xib, and add all of those PNG files, too.
As an aside, while it doesn't apparently cause the crash, the "File Owner" base class in SDNestedTableView NIB refers to a class that doesn't exist anywhere in this project. That can't be good. Anyway, you probably want to change that to SDMenuViewController or SDNestedTableViewController;
It's a little unrelated to your crash, but as I look at the project, I see a worrying construct:
SDMenuViewController *mvc = [[SDMenuViewController alloc] initWithNibName:#"SDNestedTableView" bundle:nil];
[menuView addSubview:mvc.view];
You're creating a controller, grabbing its view, and either letting the view controller fall out of scope and be released (if you were using ARC) or leaking it (if not ARC).
I wasn't entirely sure from the original question whether you were doing addSubview as a way of transitioning to a new view (which is really bad practice) or whether you were doing view controller containment. As I look at the code, it appears you're doing the latter, though you're missing a few calls in your code. You might want to read up on view controller containment. And also check out that WWDC 2011 session 102.
Anyway, those two lines of code above with the view controller alloc/init and the subsequent addSubview will leak in your non-ARC project (and would crash it if you ever went to ARC) and your view hierarchy is out of sync with your view controller hierarchy. I'd suggest you might want:
SDMenuViewController *mvc = [[[SDMenuViewController alloc] initWithNibName:#"SDNestedTableView" bundle:nil] autorelease];
[self addChildViewController:mvc];
[mvc didMoveToParentViewController:self];
[menuView addSubview:mvc.view];
Note the autorelease on that first line.
View controller containment can be powerful, but you want to make sure you do some of this basic housekeeping.
One final update:
I notice that there are some bugs that are in this code. First, your use of currentSection in item:setSubItem:forRowAtIndexPath won't work. You're setting that based upon the last expandingItem. So, if you click on one of the main items before expanding either one, the program will crash. Probably best is to eliminate the currentSection variable altogether and in item:setSubItem:forRowAtIndexPath, use item.cellIndexPath.row rather than your variable currentSection.
Unfortunately, this fix leads to a more serious problem, there appears to be an iOS 6 bug in the SDNestedTable class, itself. If you run this on iOS 6 and you expand your all of your items, scroll to the bottom and then scroll back to the top, the program will crash because the cellIndexPath property of the SDGroupItem *item returned by item:setSubItem:forRowAtIndexPath can be deallocated! If you turn on zombies in iOS 6, you'll see cellIndexPath has been released. I went and downloaded the original version and see the same problem there. The problem appears to be that cellIndexPath in SDGroupCell is defined as an assign property (which means that if iOS determines it no longer needed the indexPath it created for its own purposes, it will be released even though SDGroupCell maintains an assign reference to this released object). Just change the cellIndexPath property of SDGroupCell from assign to retain, and this iOS 6 bug goes away. I've informed the developer of SDNestedTable of this issue, but this change to retain will fix the problem of the code crashing in iOS 6.
[Edit: The author of SDNestedTable agreed with my assessment of the issue, and he reports that this issue has been fixed the latest version. - Rob]
Best wishes.
You should probably use initWithNibName: insead of just init in the first line. Not sure regarding your specific issue, but certainly something to try.
It looks like you're trying to instantiate a nib called SDNestedTableView.nib and it isn't present. Is the nib included as a project member?

initWithNibName not working

Just ran into this very frustrating problem when trying to add a new view, I have 2 different types of view: LargeCoverViewController and CoverViewController.
I created a LargeCoverViewController like this:
LargeCoverViewController *tmpCover = [[LargeCoverViewController alloc] initWithNibName:#"LargeCoverViewController" bundle:nil andIssue:issue];
That just works, but when I try to create a CoverViewController, it refuses to work
CoverViewController *tmpCover = [[CoverViewController alloc] initWithNibName:#"CoverViewController" bundle:nil andIssue:issue];
I'm thinking it has something to do with the .xib file, when I do like this it "works" again
CoverViewController *tmpCover = [[CoverViewController alloc] initWithNibName:#"LargeCoverViewController" bundle:nil andIssue:issue];
In Interface Builder the class is set properly, my view is linked up correctly. (It's basically just a copy of the LargeCoverViewController), am I still missing something?
It's getting very frustrating ...
EDIT:
My application doesn't crash, if my nibname was wrong the application should crash, which isn't the case here.
Try creating new separate XIB file rather copying whole XIB file and then copy the UI outlets and views from other XIB to this newly created XIB file.
Sometimes, Xcode gets confused with copy-pasting. I know this is not proper solution but sometimes it works. :)
When copying ViewController, the fileowner's custom class remains the same so change it to your new ViewController and once again bind your view after changing.
Is your application getting crashed on that line? Check the console for the logs. You may have got error messages or crash logs.
If you copied XIB resources from any other XIB then check for the linked outlets with objects which may not be available to this new class.
I hope this will help you and will able to resolve the issue.

Could not Load NIB for the Third Time?

IN my application i am using this code to Call my First Class Xib.Here is my Code.
-(IBAction)retryagain
{
firstview *sec=[[firstview alloc] initWithNibName:#"firstview" bundle:nil];
sec.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:sec animated:YES];
[sec release];
}
This Code works fine for 6 or 7 minutes after running my application ,but when i call this code after 6 or 7 minute. then my application Crash its give me the following in Console.
Any One can guide me how To solve this problem.any help will be appriated.Thanx in Advance.
** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle….' with name 'firstview'*
Answer :
It looks like you're trying to instantiate a nib called 'firstview'
and it isn't present. Is the nib included as a project member? In
project -> Build Phases
Make sure the .xib is added to Copy Bundle Resources
The above code is working fine for me . Please check the nib name you entered here with the actual name.
If you are using the new xcode version I would suggest to exit xcode and restart your mac, then clean the project and try again. I had some weird nib errors caused by something faulty in xcode and a restart somehow fixed them.
Another suggestion would be to delete the nib file and remake it. I had a similar problem with a nib once and recreating the file fixed everything.
I doubt it something wrong with your code, you would have encountered this error every time you tried to load the nib, not on the third time, as I understand from your question

How to avoid old xib cache on released iphone apps?

I'm developing my first iPhone app.
One day, I renamed some files including xib file and its view controller.
After that, my app began to use old xib file.
I deleted xib file, but the old xib still was used.
The code to init view controller was:
MyViewController *vc = [[MyViewController alloc] init];
I modified the code to:
MyViewController *vc = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil];
Then my app used the new xib instead of the old xib.
The question is, is it possible that old xib files are displayed not only on developing apps but also on released apps for some reasons?
Can I avoid old nix caching on released apps if I use initWithNibName: instead of init?
I think you need to remove the files in DerivedData. I've been through this sort of thing. If you're using the Simulator, I'd also reset the simulator or delete its files.
Paths:
/Users/yourname/Library/Developer/Xcode/DerivedData
/Users/yourname/Library/Application Support/iPhone Simulator
You could get fussy, but I usually delete the DerivedData directory when I am having trouble. Xcode will rebuild them in less time that it takes to worry about the problem. In the iPhoneSimulator, you can find your app fairly easily and delete that directory if you choose.
In Product->Clean and then after Execute this will be solve your problem.

'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the GameView nib but the view outlet was not set

This is not the same situation as the multitude of other similar questions here.
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the GameView nib but the view outlet was not set.'
You might be thinking "do as it says, connect the File's Owner to the View in IB!". But the thing is, I don't even HAVE a GameView.xib in my project or even in the project directory.
I do have a "GameViewController.m" and matching "GameViewController.xib" in my project. Using that GameViewController is what brings up this error, but I don't understand where it gets the idea to try and load "GameView.xib". Shouldn't it use "GameViewController.xib" instead?
If I grep my project directory, I do see it referenced from "UserInterfaceState.xcuserstate".
<string>file://localhost/Users/bemmu/Dropbox/b2/iphone/ValleyStory/ValleyStory/GameView.xib</string>
This mentioned file does not exist. I might have had a file with that name before and renamed/deleted it, but it's not being referenced to from anywhere that I can see in IB.
Did I manage to confuse xcode?
My solution was a little different.
Click on the xib in interface builder
Select File's Owner on the left
Open the File's Owner's connections inspector
If the view property isn't yet wired, control-drag it to the view icon (under the file's owner and first responder icons).
Check any nib files you're using (like MainWindow.xib). If you are loading GameViewController from a nib, check the file it's loading from (under the info tab in the inspector). Make sure it's set to "GameViewController" and not "GameView".
I had this issue as well, but had to solve it a different way. Basically, I have a view controller name MainViewController, which has a xib named MainViewController.xib. This nib has it's view property set to the File Owner which was MainViewController.
I also made a MainView.xib that contained a view that was going to be programmatically added to the view defined in MainViewController.xib and it's view. It basically encapsulated an internal view that would be in the MainViewController.xib's view, and also had it's File Owner set to MainViewController.
So basically, I wanted MainViewController.xib to load as the nib for the MainViewController object, and inside MainViewController, at some later point, I would add the internal view specified by MainView.xib.
A couple issues arose:
1.) I found in the Apple docs that when loading a view controller via storyboard or nib:
"If the view controller class name ends with the word “Controller”, as
in MyViewController, it looks for a nib file whose name matches the
class name without the word “Controller”, as in MyView.nib.
It looks for a nib file whose name matches the name of the view
controller class. For example, if the class name is MyViewController,
it looks for a MyViewController.nib file."
Therefore, you cannot have a nib called MainView.xib if you also have a nib called MainViewController and want MainViewController.xib to be the primary nib for MainViewController.
2.) Even if you delete MainView.xib or rename it to something else (MainInternalView.xib in this case), you MUST delete / clean your iOS simulator as the old nib file (MainView.xib) will still remain in the application. It doesn't overwrite the whole application package when you rebuild / rerun your application.
If you don't want to reset your content settings (perhaps you have some data you want to preserve), then right-click on your application in your iOS Simulator folder, Show Package Contents, find MainView.nib, and delete it. Xcode will NOT do this automatically for you when you rebuild, so we need to manually remove the old nib.
Overall, don't make nibs named MainViewController and MainView, i.e. nibs with the same prefix. Call MainView.xib something else, like MainInternalView.xib.
I recently solved this issue. Make sure you back up your project before following the steps given here (just in case). These steps solved my issue
Quit Xcode
Navigate to UserInterfaceState.xcuserstate located at .xcodeproj/project.xcworkspace/xcuserdata/<username>.xcuserdata and delete the file.
Reopen Xcode. Xcode will create a new UserInterfaceState.xcuserstate which will be clean.
In my case this error was produced by dumb mistake - I delete _view view
In my case, I was not using a xib at all. I needed remove the .m file from Build Phases > Compile Sources and added it back.
Given you referenced it previously it sounds like xcode hasn't ackowledged it no longer exists. From the Product menu select "Clean" and then "Build" hopefully this will get past the old reference for you.
Face the same Problem, had to change the view's name in code:
MyViewController *controller = [[MyViewController alloc] initWithNibName:#"WrongViewName" bundle:nil];
To
MyViewController *controller = [[MyViewController alloc] initWithNibName:#"RightViewName" bundle:nil];
I had multiple views, and by accident (I don't know how this happenned) but my background view didn't have a file owner, so for anyone else who has this problem in the future, make sure all your views have a file owner.
I was gettint the same error then check the classname from interface builder and see that I typed the view controller class name at the custom class attribute.
UIViewController searches for a nib with the same name as the controller when passed nil to initWithNibNamed:bundle: Check that the file name that you pass to the initializer is correct and exists!
For example:(e.g. [[CCVisitorsController alloc] initWithNibName:nil bundle:nil] then UIViewController tries to load nib with name CCVisitorsController as default.
If that file does not exist then the error you mentioned is thrown.
I had this problem because I was doing something bad in
(id) initWithCoder:(NSCoder *) coder
which the NIB loads.