XCodeでこの警告が表示されない場合があります。互換性のない型からID Nullableに割り当てる
picker.delegate = self;
コード原因の行を:incompatibaleタイプから 'ID < UINavigationControllerDelegate、UIImagePickerControllerDelegate> _Nullable' に 'MyViewController * CONST _strong'
このラインに割り当て
アプリケーションが期待どおりに動作するようにします。 それを削除するので、動作しません。しかし、私はエラーを取り除く方法を知らない。どんな助け?
代理人が割り当てられている他のメソッドは、この警告をスローしません。
View Controllerは、NavigationControllerに埋め込まれたTabBarViewControllerの一部です。
私のクラスは
UIImagePickerControllerDelegate
@interface MyViewController() <UICollectionViewDelegate, UICollectionViewDataSource, UIImagePickerControllerDelegate, UIActionSheetDelegate, UICollectionViewDelegateFlowLayout> { } ///... @end
、完全なメソッドを継承します。
UIImagePickerControllerDelegate
が私のために警告することを隠蔽するとともにUINavigationControllerDelegate
を追加- (void) showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; picker.modalPresentationStyle = UIModalPresentationCurrentContext; picker.sourceType = sourceType; picker.delegate = self; ///HERE IS THE ISSUE picker.modalPresentationStyle = UIModalPresentationFullScreen; picker.modalTransitionStyle = UIModalTransitionStyleCoverVertical; if (sourceType == UIImagePickerControllerSourceTypeCamera) { picker.showsCameraControls = YES; } [self presentViewController:picker animated:YES completion:nil]; }
問題が修正されました。あなたは、それが要件であると書かれているいくつかの文書への素早いリンクを持っていますか?なぜ他の代表者がその警告を発したのですか? –
ドキュメントは、 'UIImagePickerController'の' delegate'プロパティのために見つかりました。それは '@property(nullable、nonatomic、weak)id delegate;'として宣言されています。つまり、プロパティに割り当てられているものは、両方のプロトコルに準拠している必要があります。 –
rmaddy
ありがとうございました。これは私がちょうど記憶にコミットしなければならないものです。 –