iPhone - UIImagePickerControllerDelegate继承 [英] iPhone - UIImagePickerControllerDelegate inheritance

查看:94
本文介绍了iPhone - UIImagePickerControllerDelegate继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经向 UIViewController 添加了一个 UIImagePickerController 。我还将 UIImagePickerControllerDelegate 分配给 UIViewController



当我执行以下行时,

  myPicker.delegate =自; 

Xcode 给我发送以下消息:


警告:从不兼容类型RootViewController分配给
id


$ / $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $

$ p $ U $ >并且错误消息消失。



所以,当我添加时,我必须将两个协议添加到 UIViewController 一个 UIImagePickerController



如果 UIImagePickerController 是一个子类的文件中所述的 UINavigationController 不应该是自动的?为什么我必须添加其父代理协议,而不只是添加 UIImagePickerControllerDelegate 协议?



这是一个错误或我没有发现什么?

解决方案

正如你所说, UIImagePickerController UINavigationController 。它使用相同的委托属性,并且不声明自己的(假设的)imagePickerDelegate,因此您的委托必须符合这两个协议。这是有道理的,因为您也将相同的代理分配给 UINavigationController 部分(对于图像选择器一无所知)。



在我看来,API设计有点可疑,但无论如何, UINavigationControllerDelegate 中的所有方法都是可选的,因此可以声明您符合协议,并完成它。


I have added a UIImagePickerController to a UIViewController. I have also assigned the UIImagePickerControllerDelegate to that UIViewController.

When I execute the following line,

myPicker.delegate = self;

Xcode gifts me with the following message:

warning: assigning to id from incompatible type 'RootViewController'

Then I added the UINavigationControllerDelegate protocol to the same UIViewController and the error message vanished.

So, do I have to add both protocols to the UIViewController when I add a UIImagePickerController?

If the UIImagePickerController is a subclass of UINavigationController as stated in the docs, shouldn't this be automatic? Why do I have to add its parent's delegate protocol and not just the UIImagePickerControllerDelegate protocol?

Is this a bug or am I missing something?

解决方案

As you noted, UIImagePickerController inherits from UINavigationController. It uses the same delegate property though and doesn't declare a (hypothetical) "imagePickerDelegate" of its own, so your delegate has to conform to both protocols. It makes sense, because you're also assigning the same delegate to the UINavigationController part (that knows nothing about the image picker).

The API design is a bit questionable here in my opinion, but anyway, all methods in UINavigationControllerDelegate are optional, so it suffices to declare that you conform to the protocol and be done with it.

这篇关于iPhone - UIImagePickerControllerDelegate继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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