开发者

Trouble with loading a separate XIB for iPad or iPhone

Im having trouble figuring out how to load a separate XIB for iPad or for iPhone in a Universal app.

Its easy enough to convert the Xcode project to Universal and have separate Main view interfaces.

My problem is the secondary view and getting it to have separate interfaces for both iPad and iPhone.

Please offer any help you can give as I ha开发者_开发知识库ve been working on this issue for days without success. Thanks in advance!


I know that @indragie's answer is a very common one, but it's a common misunderstanding that will cause you a lot more work than you actually need to do.

As long as you name the xib files a certain way, they will be automatically selected for either iPhone or iPad. Check out my answer to this same problem on another post:

iOS: Using device modifiers for loading xib files?


Just add a file named MainView~ipad.xib makes it load this one i.s.o. MainView.xib when running on a iPad..


You can use UI_USER_INTERFACE_IDIOM() to check whether the application is running on an iPad or an iPhone/iPod touch:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    // Running on iPad
} else {
    // Running on iPhone or iPod touch
}

For more information on loading NIB files, read Apple's Resource Programming Guide on Nib Files. You may want to specifically check out the Loading Nib Files Programmatically section which shows how to programatiically load a NIB from within your code using NSBundle. You can then use this in conjunction with the above code to correctly load the proper NIB depending on which device you're runining on.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜