如何在没有xib文件的情况下为iPhone + iPad开发通用应用程序? [英] How to develop an universal app for iPhone + iPad without xib files?

查看:63
本文介绍了如何在没有xib文件的情况下为iPhone + iPad开发通用应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想制作一个通用版本,但我完全以编程方式创建我的UI。

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

1)我可以添加不同的视图控制器吗?类到设备特定的资源目录?或者必须在两个设备上共享课程?

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

2)如果我必须在两个设备上共享课程,那么有条件地加载什么是最安全的方法classA或classB取决于它是iPhone还是iPad设备?

2) If I must share the classes along both devices, what's the safest way to conditionally load classA or classB depending on if it's an iPhone or iPad device?

推荐答案

1)你不能将视图控制器类添加到两个地方,因为在编译时,相同的符号(即类名)将在两个地方找到,应用程序将不会链接。

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)我会说最安全方法是使用不同的.xib,但是如果你想让它只是从代码中工作,你可以创建一个只能正确加载类的单例视图管理器。然后,在其余代码中,您需要做的就是:
[MyViewManager sharedInstance] instantiateViewController:kMyDetailsView]
并将视图显示为你希望。

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.

为了确定当前的设备你可以使用这样的语句: #define iPad [UIDevice currentDevice] .userInterfaceIdiom == UIUserInterfaceIdiomPad 。它可以包含在您的前缀文件中,使其可用于整个项目。

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.

这篇关于如何在没有xib文件的情况下为iPhone + iPad开发通用应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆