我在XCode中出现了这个警告,我似乎无法摆脱它。
分配给'id< UINavigationControllerDelegate,UIImagePickerControllerDelegate> _Nullable'来自incompatibale类型'MyViewController * const _strong'
在这一行:
UIImagePickerControllerDelegate
这行代码导致应用程序按预期工作。 删除它,它不起作用。但我不知道如何摆脱错误。有什么帮助吗?
分配了委托的其他方法不会抛出此警告。
视图控制器是嵌入在NavigationController中的TabBarViewController的一部分。
我的班级继承了@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];
}
完整的方法。
var maxMb;
$scope.FileSizeOptions = ["1MB","2MB","3MB","4MB","5MB"];
$scope.$watch('selectedFileSize',function (Val) {
maxMb = Val;
console.log('File Size', maxMb);
})
var maxBytes = 1000 * 1000 * maxMb;
答案 0 :(得分:1)
除UINavigationControllerDelegate
之外,您还需要UIImagePickerControllerDelegate
。
@interface MyViewController () <UICollectionViewDelegate, UICollectionViewDataSource, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIActionSheetDelegate, UICollectionViewDelegateFlowLayout> {
}
答案 1 :(得分:0)
添加UINavigationControllerDelegate
以及UIImagePickerControllerDelegate
会隐藏警告。
在UIKit中,图像选择器的委托被指定为:
@property(nullable,nonatomic,weak) id <UINavigationControllerDelegate, UIImagePickerControllerDelegate> delegate;
来自文档:
图像选择器的委托对象。
<强>声明强>
<强> SWIFT 强>
weak var delegate: protocol<UIImagePickerControllerDelegate, UINavigationControllerDelegate>?
<强>目的-C 强>
@property(nonatomic, weak) id<UINavigationControllerDelegate, UIImagePickerControllerDelegate> delegate
<强>讨论强>
当用户选择图像或电影或退出选择器界面时,代理会收到通知。代理人还决定何时关闭选择器界面,因此您必须提供代理人才能使用选择器。如果此属性为零,则如果您尝试显示,则会立即解除选择器。