简体   繁体   中英

iPhone - Why am I getting this error when the view mapping is correct?

My iPhone app was running fine. I added a component to my xib file (an activity indicator). I have created my own init method and am using the XIB name in the init method. Now I get this error when I do a pushViewController

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "ModelThumbnailView" nib but the view outlet was not set.'

I know this usually crops up when the viewcontroller is not mapped to the view in the xib. But all mappings are fine. I even deleted the class and xib and created them again. The init method is also not returning a nil. But I still get the exception as soon as I call a pushViewController with the object of this class.

Any ideas why?

Edit

Was just debugging and called a method in the viewcontroller before calling a pushViewController on it. The debugger shows that the nib name is set properly, the bundle is nil (coz thats what am passing) but the view is also nil. No idea why!!!

**Posting the code in case it helps **

MyThumbnailViewController *modCont = [[[MyThumbnailViewController alloc] initWithNibName:@"MyThumbnailView" bundle:nil] autorelease];
[modCont setImgName:imgName count:numOfValues andIndex:0];

[[self navigationController] pushViewController:modCont animated:YES]; //This gives the exception

This is the viewDidLoad of the MyThumbnailViewController class. The control never reaches here

- (void)viewDidLoad {
    self.navigationItem.title = imageName;
    self.navigationItem.hidesBackButton = NO;
    [[self navigationController] setNavigationBarHidden:NO];
}

I removed the custom init method but still getting the same error.

SOLVED

Just created the whole thing again and now it works fine, though I don't see ANY differences in both the things!

I'm sure you tried this already but just in case have you set a breakpoint at the location before the method is called to handle your pushView and step through the code to see where the exception is being thrown. This sometimes helps. I'll check back later to see what you find out and to see if I can offer any more help.

Sounds strange, but just to be safe maybe double check the following again: Open IB and select File's Owner. Then in the Identity Inspector make sure the Class is set your custom View Controller. Open the Connections Inspector and make sure that the view Outlet is connected to the View in the NIB (this is what the exception is complaining about).

Save the XIB File and close IB. Then in XCode select Build->Clean All Targets and try running your app.

I have seen IB and XCode drifting apart more than once, me eagerly editing Views in IB that my App would never load because I did not add them to my project by accident. So I can feel your pain :-)

I got this same error - after poking around I reattached the VIEW OUTLET (in File's Owner) to the VIEW in VIEW CONTROLLER (I just connected to the main part of the VIEW screen - sorry I am new to all this so I am sure I am not calling these things by the correct name) and that fixed it. It had worked before, but something I did must have broken that link.

FogCityFun

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM