Steven Bennett
Steven Bennett

Reputation: 309

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:

- (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:

#import <MobileCoreServices/MobileCoreServices.h>

This is how I'm instantiating the 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];

    // ...
}

Upvotes: 0

Views: 973

Answers (1)

Rob
Rob

Reputation: 438287

You can get these sorts of cryptic errors if you've have mismatched braces or parentheses in the method preceding 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.

In this case, it's because the completionHandler block of the sendAsynchronousRequest method is not terminated in the preceding method, cellForItemAtIndexPath.

Upvotes: 1

Related Questions