如何使一个通用的iPhone / iPad应用程序以编程方式使用UISplitViewController和UINavigationController? [英] How do I make a universal iPhone / iPad application that programmatically uses UISplitViewController and UINavigationController?

查看:159
本文介绍了如何使一个通用的iPhone / iPad应用程序以编程方式使用UISplitViewController和UINavigationController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里找不到一个好的答案。我使用UINavigationController为我的iPhone应用程序,一切都是以编程方式生成,在Interface Builder中没有。我试图将我的应用程序移植到iPad,使用UISplitViewController和我现有的UINavigationController,但我不知道我应该有我的程序的逻辑分离的视图控制器的iPhone或iPad。

I couldn't find a good answer anywhere to this. I am using a UINavigationController for my iPhone app, with everything is generated programmatically, nothing in Interface Builder. I am trying to port my app to iPad, using a UISplitViewController and my existing UINavigationController, but I am not sure where I should have the logic of my program separating the view controllers for iPhone or iPad.

我设置我的主文件以使用不同的应用程序委托,还是使用相同的应用程序委托并有条件地在其中设置用户界面?

Do I set up my main file to use a different app delegate or do I use the same app delegate and have the user interface conditionally set up within it?

除此之外,每当我尝试在模拟器上编译我的应用程序时,它不能识别UISplitViewController或甚至检查类是否存在的条件。

Besides this, whenever I try to compile my app on the simulator it does not recognize the UISplitViewController or even the condition in which I check if the class exists.

可以让别人把我朝着正确的方向,记住我不使用任何xibs?

Can please someone put me in the right direction, remembering that I am not using any xibs?

推荐答案

如果您想查看使用拆分视图的完全编程式iPhone / iPad界面的示例,您可以下载我的应用程序的源代码 Molecules

If you want to see an example of a completely programmatic iPhone / iPad interface that uses a split view, you can download the source code of my application Molecules.

在该应用程序中,我使用一个应用程序委托,其中存在用户界面惯例(iPad或iPhone)。对于iPhone,我实例化了一个根视图控制器,它管理该设备的适当接口。对于iPad,我首先创建一个UISplitViewController并将其附加到根窗口,然后创建我的iPad特定的根视图控制器,并将其放置为分割视图控制器的详细视图(具有用于项目选择的导航控制器

Within that application, I use one application delegate, but I set up the interface differently depending on which user interface idiom is present (iPad or iPhone). For the iPhone, I instantiate a root view controller which manages the appropriate interface for that device. For the iPad, I first create a UISplitViewController and attach it to the root window, then create my iPad-specific root view controller and place it as the detail view of the split view controller (with a navigation controller that I use for item selection as the left-hand controller for the split view).

再次,我建议您查看该应用程序项目,看看我是如何通过编程方式设置它的。代码在BSD许可下可用,因此您可以将其复制并粘贴到您自己的应用程序中。

Again, I recommend looking at that application project to see how I set this up programmatically. The code's available under a BSD license, so you can copy and paste this into your own application if you'd like.

至于编译错误,您将需要使用升级iPad的当前目标菜单选项将应用程序目标迁移为通用应用程序。一旦完成,将您的构建SDK设置为3.2。转到您的应用程序的构建设置,并将其部署目标设置为您希望在应用程序中支持的最早的操作系统(3.0是您可以访问的最远的目录)。

As far as the compilation errors you're getting, you will need to migrate your application target to be a universal application using the "Upgrade Current Target for iPad" menu option. Once that has completed, set your build SDK to 3.2. Go to your application's build settings and set its Deployment Target to the earliest OS you want to support with your application (with 3.0 being the farthest back you can go).

<最后,你将需要弱链接UIKit。有关如何操作,请参阅我的答案 here 。如果您使用iOS 4.2或更高版本的SDK构建框架,则不再需要弱连接框架。通过查看它们的 +类方法是否返回 nil ,在运行时检查是否存在合适的类。

Finally, you will need to weak-link UIKit. For how to do that, see my answer here. Weak linking of frameworks is no longer necessary if you are building using the iOS 4.2 or later SDK. Simply check for the presence of the appropriate classes at runtime by seeing if their +class method returns nil.

这篇关于如何使一个通用的iPhone / iPad应用程序以编程方式使用UISplitViewController和UINavigationController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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