且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-11-03 13:41:45

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.