Firemarble Firemarble - 1 year ago 122
iOS Question

Assigning to ID Nullable from Incompatible Types

I have this warning showing up in XCode that I can't seem to get rid of.

Assigning to 'id < UINavigationControllerDelegate, UIImagePickerControllerDelegate > _Nullable ' from incompatibale type 'MyViewController * const _strong'

on this line:

picker.delegate = self;

This line of code causes the application to work as expected. So removing it, it doesn't work. But I don't know how to get rid of the error. Any help?

Other methods that have delegate assigned are not throwing this warning.

The view controller is a part of a TabBarViewController that is embedded in a NavigationController.

My class inherits the

@interface MyViewController () <UICollectionViewDelegate, UICollectionViewDataSource, UIImagePickerControllerDelegate, UIActionSheetDelegate, UICollectionViewDelegateFlowLayout> {


And the complete method.

- (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];

enter image description here

Answer Source

You need both the UINavigationControllerDelegate in addition to UIImagePickerControllerDelegate.

@interface MyViewController () <UICollectionViewDelegate, UICollectionViewDataSource, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIActionSheetDelegate, UICollectionViewDelegateFlowLayout> {