0

I'm trying to learn iOS (4.3) programming and got stuck on this. I'm using a Windows-based app, and have it set to that it's using both an iPhone and iPad view.

It crashes on:

self.window.rootViewController = self.viewController;

And I am getting the error

'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "SwitchViewController" nib

However, the view outlet was not set.

Most things for this error say to make sure your view is hooked up to your controller properly and mine is hooked up. The code works fine for the iPhone view, it doesn't work for the iPad one. The delegates, and other connections are the same in each view, which might be the problem, but I don't know what would need to be different.

I'm using the naming convention here to load the views for the different OSs. I thought this meant that the program was automatically going to pick out the right view as long as I had _iPhone/_iPad appended to the end of the name, and it's behavior did change when I added the iPad view so I think it's reaching it.

The iPad code worked with a generic view before I separated views between iPhone (originally the generic view) and iPad, and I didn't change any code upon adding the view.

double-beep
  • 5,031
  • 17
  • 33
  • 41
orangeberri07
  • 173
  • 1
  • 11
  • I'm assuming that you have your target set to universal app? In that case any code where you handle view switching would be good to see. Sounds like an interesting error... Also are you sure that you have ALL your outlets set? The error you are getting seems to indicate otherwise. – Karoly S Aug 25 '11 at 20:26
  • Specifically I think the error might be referring to you needing to connect the File Owner's view outlet to the actual xib view, for your SwitchViewController. – Karoly S Aug 25 '11 at 20:32
  • I uploaded the whole project if you're willing to take a look at it. Excuse the random button names. – orangeberri07 Aug 26 '11 at 13:29
  • I'm looking at it now, it isn't crashing for me, but its only displaying your MainWindow_iPad.xib. I'm guessing that's not accurate? – Karoly S Aug 26 '11 at 14:41
  • No, I'm getting a full-out crash. Maybe I'll try remaking the project in a new folder... Thanks! – orangeberri07 Aug 26 '11 at 18:43
  • Yea give that a shot. I looked through all the parts that I think could be wrong but without it actually crashing I couldn't find anything specific, it all looked fine to me. In cases where you absolutely cannot figure out whats wrong, if you arent terribly far along, I usually just remake my project if I've been stuck on a part for a long time, and take it slower. Also introducing some kind of checkpoints where you save the states(be it source control or snapshots, or just copying the folder) so if something goes wrong you have a clean build to start from and try again helps immensely . – Karoly S Aug 26 '11 at 20:19

2 Answers2

0

In your - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil add this line at the beginning:

if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) nibNameOrNil = @"iPadXibName";

And make sure that the ipad's xib has all the proper outlets connected (which is probably the case if it worked as an ipad-only implementation, but you may have added something or forgot to add something when merging iphone and ipad versions).

SVD
  • 4,743
  • 2
  • 26
  • 38
0

I remade my code in a new project and it worked fine right away. Something was wrong with the original project.

orangeberri07
  • 173
  • 1
  • 11