开发者

iPad-specific View crashes on launch

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.开发者_JAVA百科 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.


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).


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜