我在下一行的图片选择器Use of undeclared identifier 'imagePickerController'
代表中收到错误didFinishPickingMediaWithInfo
:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
我已经将协议添加到界面中:
@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];
// ...
}
答案 0 :(得分:1)
如果didFinishPickingMediaWithInfo
之前的方法中的大括号或圆括号不匹配,您可能会遇到这些类型的神秘错误。如果选择所有代码然后按 control - i (或选择“编辑器” - “结构” - “重新缩进”),则可以识别缺失的大括号当它重新缩进你的代码时,丢失的括号会跳出来。
在这种情况下,这是因为completionHandler
方法的sendAsynchronousRequest
块未在前面的方法cellForItemAtIndexPath
中终止。