开发者

How to develop an universal app for iPhone + iPad without xib files?

I want to make an universal build, but I create my UI entirely programmatically.

1) Can I add my different view controller classes to the device-specific resources directories? Or must classes be shared along both devices?

2) If I must share the classes along both devices, what's the safest way to conditiona开发者_如何转开发lly load classA or classB depending on if it's an iPhone or iPad device?


1) You can not add the view controller classes in two places, because at compile time the same symbol (i.e. class name) will be found in two places and the app will not link.

2) I would say that the safest way would be to have different .xib , but if you want to meke it work just from code, you could create a singleton view manager that only does the correct class loading. Then, in the rest of your code, all you need to do is: [MyViewManager sharedInstance] instantiateViewController:kMyDetailsView] and display the view as you desire.

For determining the current device you can use a statement like this: #define iPad [UIDevice currentDevice].userInterfaceIdiom==UIUserInterfaceIdiomPad. It can be included in your prefix file making it available to the whole project.


On every view controller you can do a device check to see which device is running your app and accordingly build your UI. ie, use only one set of view controllers and in the *.m files, in an if-else loop, build your UI accordingly.

Refer to this post to do device checks: Determine device (iPhone, iPod Touch) with iPhone SDK

PS: In your if-else, do an if(iPad){} else{} check as a best practice, since, often times than not, people forget to check for iPod Touch if they do if(iPhone){}else{}

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜