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

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.

Related

App crashes when moving from UITableView to second view

i have a UITableView and a second web view that i wish to move to when a cell is touched.
my problem is the program is crashing with
'NSInvalidArgumentException', reason: 'Receiver (<ViewController: 0x1e583890>) has no segue with identifier 'testing''
*** First throw call stack:
(0x326342a3 0x3a35197f 0x34647e31 0x78633 0x344fe28d 0x34580f81 0x32f42277 0x326095df 0x32609291 0x32607f01 0x3257aebd 0x3257ad49 0x361512eb 0x34490301 0x7724f 0x3a788b20)
libc++abi.dylib: terminate called throwing an exception
i have looked at every solution posted on here, tutorials and still cant see what is wrong.
I am new to story boards and iOS
here is some pieces of my code
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"testing" sender:self];
}
yes i do have a segue called "testing"
i tried commenting out [self performSegueWithIdentifier:#"testing" sender:self];
and using
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([segue.identifier isEqualToString:#"testing"]){
NSLog(#"identifier is equal");
webviewViewController *ViewController =segue.destinationViewController;
}
but when the cells were pressed then nothing happened, and #"identifier is equal" didnt show up in the log.
hope this helps
its telling that you not have the segue named "testing" . be sure of it,if you have mentioned segue, check for spelling.
else if you are not mentioned segue,plz mention it by clicking segue & writing name for it in inspector window
I've had this error before, and in fact this answer right here helped me out.
I had renamed my Storyboard and forgot to change it in the other necessary places. Make sure all of your information matches up correctly and that you're using the right version of your Storyboard.
Once you're done, make sure to uninstall the app on your simulator or device and retry.
ok i have found the problem, I had added a navigationcontroller to the ViewController in the app delgate file didfinishlaunchingithoptions, i had forgotten about this.
I have removed it and naturally it all works
thanks alot for all the answers

Attached a new controller to existing storyboard

I'm doing some iPhone development, and I'm using Storyboards to mock up and expedite my development.
I didn't came from the conventional way of doing things, do I have to?
Anyway, I have storyboard,
TableViewController
NavigationController->ViewController->TabViewController [
AnotherViewController
I wanted to add a new ViewController attached to the TableViewController so that when I click on the row item it will show it on the other view, however;
I can't find a way how to connect the new ViewController into the TableViewController (vice versa)
So I tried the conventional way of doing things on the
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
I put the ff:
CViewController *controller = [[CViewController alloc] initWithNibName:????? bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
I tried to give the Controller an identifier on the Attributes Inspector but does not work and is giving me the following crash stack:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/paulvincentong/Library/Application Support/iPhone Simulator/5.1/Applications/A1C369F8-9EAD-4794-8861-945C73F7FE0B/SyncProto.app> (loaded)' with name 'ControllerViewName'
If I remove the Identifier, I'll get a no NibName exception;
What should I do? I know it should just be the same as I was able to go as far as four levels of relating controllers, there might be something at the back of my head that is confusing me...
TIA,
try this in your cellForRow
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
*)indexPath{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Storyboard"
bundle:nil];
ViewCont * view = (ViewCont *) [storyboard
instantiateViewControllerWithIdentifier:#"view"];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
[self view animated:YES completion:nil];
}
Make sure you have set your storyboard also in the project manager.
Are u using IB? There you can drag directly.
Otherwise in storyboards you don't use the push method you stated. You use performSegueWithIdentifier. Storyboards are about segues. You can segue directly or use target actions.
Again the strength of storyboards is in their visual representation. Use IB.
Otherwise you might also consider delegation (ESP for ipad).
After playing around... I found the suitable answer to my question;
My problem appears to be cause of
Confusion - a new programmer's dilemma.. tho the question is a common one, we can never really deviate if its really the same with those already existing and asked before only up until we tried it ourselves and found out that it really was.
The solution could vary from case to case; and for me I tried to do the ff:
Approach 1: (using the "instantiateViewControllerWithIdentifier") with a segue arrow
Create the view to be added
Position your mouse pointer to the Nib element source view controller you want to trigger the segue then hold control
Drag you mouse to the destination view controller
A popup will appear, choose your segue type (push, modal, custom) then automatically xcode will create the necessary connections
Select your destination view controller and on the Attribute Inspector there is a Collapsible group with Identifier field -> on this field you will put your custom identifier for the view
So the source code would look like;
ViewController *view = [self.storyboard instantiateViewControllerWithIdentifier:#"CustomViewName"];
[self.navigationController pushViewController:view animated:YES];
Approach 2: (using the "instantiateViewControllerWithIdentifier") without the segue arrow
Create the view to be added
Provide the new controller with the necessary identifier then you're good to go
Using the same source as defined above
However, using this approach will break your storyboard's consistency and why use this? (still something I have to find out), its not obvious when you start looking for the segue arrow that was never there, albeit it works.
This code will not work on the basis that I don't have a nib with a name ????,
CViewController *controller = [[CViewController alloc] initWithNibName:????? bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
and since its on a storyboard and assuming everything was done using the storyboard, then time to forget about the nibName because it will never happen..
Hope that this idea would help a few...
Learning is a thorough process yet its a very interesting thing to do...
Thanks.

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?

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

iOS add rootViewController to window causes delegate not found error

I'm creating an application that first loads a settings screen which displays a series of text fields and labels asking the user for input. This is all working fine.
What I then want to do is once this data has been input, it comes up with the main application interface.
What is happening though is that when I'm telling the application delegate to load the main view, it says that the viewController isn't key value complaint for the key delegate.
The code I'm using to create the viewController is:
CustomViewController *viewController = [[CustomViewController alloc] initWithNibName:#"CustomViewController" bundle:nil];
self.window.rootViewController = viewController;
If anyone thinks that UIWindow doesn't have a rootViewController property, please check the documentation. That's what I did, and it does have one.
Any help with figuring this out would be greatly appreciated.
For those that like full debug info, this is what I get from xcode.
2011-06-18 15:03:15.474 Some App[15596:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<CustomViewController 0x53368b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key delegate.'
Thanks,
Matt.
Most likely you try to use delegate somewhere in your xib file, but it doesn't exist in your CustomViewController class.
Check the connections in your nib file and remove the one that connects to the non existing delegate.
The rootViewController property was only recently introduced and might not be available on devices running an older version of iOS.
You want to have a UINavigationController as the root view controller of your application and subsequent pages you simply push onto it. If you don't want animation, then do animate:NO. If you don't need a navigation bar, then hide that as well.
It is generally preferable to use one of the existing container view controllers over swapping them out yourself.