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

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

问题描述

我已将 UIImagePickerController 添加到 UIViewController.我还将 UIImagePickerControllerDelegate 分配给该 UIViewController.

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

当我执行以下行时,

myPicker.delegate = self;

Xcode 送给我以下信息:

Xcode gifts me with the following message:

警告:分配给ID来自不兼容的类型RootViewController"

warning: assigning to id from incompatible type 'RootViewController'

然后我将 UINavigationControllerDelegate 协议添加到相同的 UIViewController 并且错误消息消失了.

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

那么,当我添加 UIImagePickerController 时,是否必须将这两个协议都添加到 UIViewController 中?

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

如果 UIImagePickerController 是文档中所述的 UINavigationController 的子类,这不应该是自动的吗?为什么我必须添加其父级的委托协议,而不仅仅是 UIImagePickerControllerDelegate 协议?

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?

推荐答案

如您所见,UIImagePickerController 继承自 UINavigationController.它使用相同的 delegate 属性,并且没有声明自己的(假设的)imagePickerDelegate",因此您的委托必须符合这两种协议.这是有道理的,因为您还将相同的委托分配给 UINavigationController 部分(对图像选择器一无所知).

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).

我认为这里的 API 设计有点问题,但无论如何,UINavigationControllerDelegate 中的所有方法都是可选的,因此只需声明您符合协议并完成它即可.

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天全站免登陆