assigning to uiimagepickercontrollerdelegate from incompatible type

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

When I try to do

myPicker.delegate = self;

Xcode gifts me with this 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 ViewController when I add a UIImagePickerController?

if the UIImagePickerController is a subclass of UINavigationController as stated on 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?

thanks.

 

 

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.

转载于:https://www.cnblogs.com/lisa090818/p/3363254.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值