仅使用 iPhone OS 3.2 类
您将如何编写一个使用 iPhone OS 3.2 中引入的类(例如 UIPopoverController
和 UISplitViewController
)的通用应用程序?在 Jeff LaMarche 的博客中,Ole 提供了一种实例化这些对象的方法;您可以像这样实例化一个 UIPopoverController
:[NSClassFromString(@"UIPopoverController") alloc]
。
这对于在代码中实例化这些类来说很好,但是协议及其方法呢?我的 iPad 应用程序使用 UISplitViewController
并有一个需要符合 UISplitViewControllerDelegate
和 UIPopoverControllerDelegate
的类。你会如何声明这一点?您将如何使用如下方法?
- (void)splitViewController:(UISplitViewController *)svc willHideViewController:(UIViewController *)aViewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)pc
其中方法调用需要传入 UISplitViewController
?
How would you write a universal app that uses classes introduced in iPhone OS 3.2, such as UIPopoverController
and UISplitViewController
? On Jeff LaMarche's blog about this, Ole provides a method for instantiating these objects; you would instantiate a UIPopoverController
like so: [NSClassFromString(@"UIPopoverController") alloc]
.
This is fine for instantiating these classes in code but what about protocols and their methods? My iPad app uses a UISplitViewController
and has a class that needs to conform to the UISplitViewControllerDelegate
and UIPopoverControllerDelegate
. How would you declare this? And how would you work with a method such as the following?
- (void)splitViewController:(UISplitViewController *)svc
willHideViewController:(UIViewController *)aViewController
withBarButtonItem:(UIBarButtonItem *)barButtonItem
forPopoverController:(UIPopoverController *)pc
where the method call requires UISplitViewController
to be passed in?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将其保留在那里,因为这些
UISplitViewController*
等仅充当编译器进行类型检查的类型(与实际符号需要的[UISplitViewController alloc]
不同)被链接)。如果无法编译,请在文件开头添加
@class UISplitViewController, UIPopoverController;
。You can leave it there, since these
UISplitViewController*
etc only serves as a type for the compiler to do type-checking (unlike[UISplitViewController alloc]
which an actual symbol needs to be linked).Add a
@class UISplitViewController, UIPopoverController;
at the start of the file if it doesn't compile.而且,就像这样,我发现如果您弱链接 UIKit 框架,这不是问题。我在 Stack Overflow 上找到了这个。
And, just like that, I see that this isn't a problem if you weak-link the UIKit framework. I found this right here on Stack Overflow.