如何在没有xib文件的情况下为iPhone + iPad开发通用应用程序?

编程入门 行业动态 更新时间:2024-10-10 09:24:59
本文介绍了如何在没有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开发通用应用程序?

本文发布于:2023-10-29 00:29:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1538199.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   情况下   文件   如何在   iPhone

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!