gpt4 book ai didi

ios - 使用未声明的标识符 'imagePickerController'

转载 作者:行者123 更新时间:2023-11-29 01:39:43 26 4
gpt4 key购买 nike

我在以下行的图像选择器 didFinishPickingMediaWithInfo 委托(delegate)中收到错误使用未声明的标识符“imagePickerController”:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

我也将协议(protocol)添加到了界面中:

@interface MyMediaController : UIViewController <UICollectionViewDelegate, UICollectionViewDataSource, UIImagePickerControllerDelegate, UINavigationControllerDelegate>

此外,我还添加了 MobileCoreServices.framework 二进制文件以与该二进制文件链接并按如下方式导入:

#import <MobileCoreServices/MobileCoreServices.h>

这就是我实例化 imagePicker 的方式:

- (IBAction)takePhotoButtonAction:(id)sender {
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.mediaTypes = @[(NSString *) kUTTypeImage];
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:nil];
self.isNewMedia = YES;
}
}

关于为什么我收到此错误有什么想法吗?这很奇怪,因为这之前是有效的,但似乎没有特殊原因就停止了工作。

编辑:这是错误行之前的代码:

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return CGSizeMake(collectionView.bounds.size.width / 2 - 15, 150);
}

- (MyMediaCollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MyMediaCollectionViewCell *cell = (MyMediaCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"MyMediaCollectionViewCell" forIndexPath:indexPath];
AccountModel *account = [AccountModel getInstance];
NSString *fileName = [[self.mediaResults objectAtIndex:indexPath.row] objectForKey:@"filename"];
NSString *urlPath = [NSString stringWithFormat:@"https://s3-us-west-2.amazonaws.com/developd/premium_media/%@/thumb.%@", account._id, fileName];

[NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlPath]] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
UIImage *cellImage = [UIImage imageWithData:data];
cell.imageView.image = cellImage;
[cell setTag:indexPath.row];

return cell;
}

#pragma mark UIImagePickerControllerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = info[UIImagePickerControllerMediaType];

[self dismissViewControllerAnimated:YES completion:nil];

// ...
}

最佳答案

如果您在 didFinishPickingMediaWithInfo 之前的方法中有不匹配的大括号或括号,您可能会遇到这些神秘的错误。如果您选择所有代码,然后按 control-i(或选择“Editor”-“Structure”-“Re-Indent”),则可以识别缺少的大括号,然后当它重新缩进您的代码时,丢失的大括号会跳出来。

在这种情况下,是因为 sendAsynchronousRequest 方法的 completionHandler block 没有在前面的方法 cellForItemAtIndexPath 中终止。

关于ios - 使用未声明的标识符 'imagePickerController',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32546656/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com