Could not Load NIB for the Third Time? - iphone

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

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.

View Navigation Issue - 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle

I'm new to programming in objective C so I have a feeling this is just something really stupid I'm doing or failing to do...
I have an iPhone app and am trying to navigate from one view to another. I hooked up a segue and when I call it, like this:
[self performSegueWithIdentifier:#"ShowPolicyInformation" sender:sender];
it works just fine. But now I want to pass a value to my new view, and from what I can tell I can't do that with a segue. So I setup some properties on it and am trying to navigate to it more manually:
PolicyInfoViewController *pol =[[PolicyInfoViewController alloc] initWithNibName:#"PolicyViewController" bundle:nil];
pol.PropertyOne=txtOne.text;
pol.strPropertyTwo=txtTwo.text;
[[self navigationController] pushViewController:pol animated:YES];
When I replace the performSeque code with the code above, it builds fine, but I get this error when I run it:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'MainMobileViewController''
When I search for help with this issue, all of the suggests that are shown talk about making sure the .xib file is named correctly....and here is where I'm completely lost, because I don't have any .xib files that I can see. I'm working with a storyboard and just drag/dropping the views onto it and connecting it to classes I create. So...what newbie mistake am I making? What am I missing? I am working with xCode 4.4, so is this just different code than what I'm finding in these searches? Any help or advice would be greatly appreciated.
You can perform this by using Story Board only and not having to have a separate nib file for the PolicyInfoViewController... It would probably easier for you to do it this way.
so in keeping the first line of code:
[self performSegueWithIdentifier:#"ShowPolicyInformation" sender:sender];
You would need to override this method to manipulate properties of the PolicyInfoViewController
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:#"ShowPolicyInformation"])
{
PolicyInfoViewController *pol = segue.destinationViewController;
pol.PropertyOne=txtOne.text;
pol.strPropertyTwo=txtTwo.text;
}
}
So what is happening here? First bit of code you are telling the control to perform the particular segue from story board. Second bit you are telling control what to do when a particular segue is called.

Could not load NIB in bundle - inspiration needed

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

Connecting a nib to files owner problem

So I am upgrading my iPhone app to be universal. I upgraded the project and than created a new nib for one of my classes. I set the custom class for that nib to my viewController and dragged the view from files owner to the nib. All worked fine. But than the second time I ran it, I got the following error:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the
"viewControlleriPad" nib but the view outlet was not set.'*** Call stack at first
throw:
So I disconnected view from the nib, than reconnected it and it worked. So basically the pattern seems to be every time I link it, it works once. This seems really weird. Thanks in advance for any help.
In the new XIB that is created I suppose you have not associated the class of the File's Owner with the class of the view controller
Also you have not set the view outlet of the File's Owner.
Hope you get it.
If you need more help than please let me know.
EDIT:
Please refer to this question:
Iphone sdk tabbar View outlet was not set
EDIT-2:
View Objects don't connect to the File's Owner
This happened to me before as well. It would be worth a try to try the following in this order:
Copy + paste your nib in xcode, rename the old one, name the new one to the old name
Rebuild the nib from scratch if it is not too much trouble
Restart your Mac
Examine the XML for the nib for any oddness
(#2 worked for me)