我在XCode中显示了我似乎无法摆脱的警告。


  从不兼容类型'MyViewController * const _strong'分配给'id _Nullable'


在这条线上:

picker.delegate = self;

这行代码使应用程序按预期工作。因此,删除它不起作用。但是我不知道如何摆脱错误。有什么帮助吗?

指派了委托的其他方法不会引发此警告。

视图控制器是TabBarViewController的一部分,该TabBarViewController嵌入在NavigationController中。

我的课继承了UIImagePickerControllerDelegate

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

}
///...
@end


以及完整的方法。

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


ios - 从不兼容类型分配给ID为空-LMLPHP

最佳答案

UINavigationControllerDelegate外,还需要两个UIImagePickerControllerDelegate

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

}

10-08 05:58