zoukankan      html  css  js  c++  java
  • 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.

  • 相关阅读:
    tomcat内存调优
    loadrunner 商城项目随机选书
    loadrunner 脚本调试之添加日志
    Macaca自动化测试工具环境搭建
    python selenium 自动化测试图片识别1
    SQL——数据插入
    SQL集合操作
    SQL——多表查询
    SQL简单查询操作
    PV操作——实力模型2
  • 原文地址:https://www.cnblogs.com/lisa090818/p/3363254.html
Copyright © 2011-2022 走看看