[英]Use of undeclared identifier 'imagePickerController'
我在以下行的图像选择器didFinishPickingMediaWithInfo
委托中收到错误Use of undeclared identifier 'imagePickerController'
的错误:
- (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];
// ...
}
如果在didFinishPickingMediaWithInfo
之前的方法中花括号或括号不匹配,则可能会出现这类隐秘错误。 如果选择所有代码,然后按Control - i (或选择“ Editor”-“ Structure”-“ Re-Indent”),则可以识别丢失的花括号,当它重新插入代码时,丢失的花括号将跳出在你身上
在这种情况下,这是因为sendAsynchronousRequest
方法的completionHandler
块未在前面的方法cellForItemAtIndexPath
终止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.