我在XCode中顯示了我似乎無法擺脫的此警告。從不兼容類型中分配ID可空的
分配到 'ID < UINavigationControllerDelegate,UIImagePickerControllerDelegate> _Nullable' 從incompatibale類型 'MyViewController * const的_strong'
在這條線:
picker.delegate = self;
這行代碼的原因應用程序按預期工作。 因此刪除它,它不起作用。但我不知道如何擺脫錯誤。任何幫助?
有委派委派的其他方法不會引發此警告。
視圖控制器是嵌入在NavigationController中的TabBarViewController的一部分。
我的類繼承的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];
}
解決了問題。你碰巧有一個快速鏈接到一些文件,說明這是一個要求?其他代表爲什麼會發出這樣的警告? –
該文檔是爲'UIImagePickerController'的'delegate'屬性找到的。它被聲明爲@屬性(可空,非原子,弱)id委託;'。這意味着無論分配給財產必須符合這兩個協議。 –
rmaddy
非常感謝。這是我必須承諾記憶的一個。 –