简体   繁体   English

使用未声明的标识符“ imagePickerController”

[英]Use of undeclared identifier 'imagePickerController'

I'm receiving the error Use of undeclared identifier 'imagePickerController' in my image picker didFinishPickingMediaWithInfo delegate on the following line: 我在以下行的图像选择器didFinishPickingMediaWithInfo委托中收到错误Use of undeclared identifier 'imagePickerController'的错误:

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

I've added the protocol's to the interface as well: 我也将协议添加到了接口:

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

Also, I added the MobileCoreServices.framework binary to be linked with the binary and imported it as so: 另外,我添加了MobileCoreServices.framework二进制文件以与该二进制文件链接并按以下方式导入它:

#import <MobileCoreServices/MobileCoreServices.h>

This is how I'm instantiating the imagePicker: 这就是我实例化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;
    }
}

Any ideas on why I'm receiving this error? 关于我为什么收到此错误的任何想法? It's odd because this was working previously, and just seemed to stop working for no particular reason. 奇怪的是,这以前曾起作用,而且似乎无故停止工作。

Edit: Here's the code preceding the error line: 编辑:这是错误行之前的代码:

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

    // ...
}

You can get these sorts of cryptic errors if you've have mismatched braces or parentheses in the method preceding didFinishPickingMediaWithInfo . 如果在didFinishPickingMediaWithInfo之前的方法中花括号或括号不匹配,则可能会出现这类隐秘错误。 You can identify missing braces if you select all of your code and then press control - i (or chose "Editor" - "Structure" - "Re-Indent") and as it re-indents your code, the missing brace will jump out at you. 如果选择所有代码,然后按Control - i (或选择“ Editor”-“ Structure”-“ Re-Indent”),则可以识别丢失的花括号,当它重新插入代码时,丢失的花括号将跳出在你身上

In this case, it's because the completionHandler block of the sendAsynchronousRequest method is not terminated in the preceding method, cellForItemAtIndexPath . 在这种情况下,这是因为sendAsynchronousRequest方法的completionHandler块未在前面的方法cellForItemAtIndexPath终止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM