【问题标题】:Problem UIImagePickerControllerDelegate, didFinishPickingMediaWithInfo not called问题 UIImagePickerControllerDelegate,没有调用 didFinishPickingMediaWithInfo
【发布时间】:2011-04-07 12:17:33
【问题描述】:

大家好, 我知道这个问题被问得更频繁了,但他们的问题的答案似乎在这里并不适用。

我的 didFinishPickingMediaWithInfo 方法没有被调用:(

这是我的代码:

.h 文件:

#import <UIKit/UIKit.h>


@interface DevicePictureController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate> {

    UIImageView *photo;
    UIButton *selectPhoto;
    UIButton *takePhoto;
    NSMutableDictionary *listLocations;
    NSMutableDictionary *listDevices;
    UIImagePickerController *picker;
}

@property (nonatomic, retain) IBOutlet UIImageView *photo;
@property (nonatomic, retain) IBOutlet UIButton *selectPhoto;
@property (nonatomic, retain) IBOutlet UIButton *takePhoto;
@property (nonatomic, retain) UIImagePickerController *picker;

-(IBAction)selectPicture:(id)sender;
@end

.m 文件: #import "DevicePictureController.h"

@implementation DevicePictureController
@synthesize photo, selectPhoto, takePhoto, picker;

- (void)viewDidLoad
{
    [super viewDidLoad];
    listLocations = [[NSMutableDictionary alloc] init];
    listDevices = [[NSMutableDictionary alloc] init];
    picker = [[UIImagePickerController alloc] init];
}

-(IBAction)selectPicture:(id)sender {

    picker.delegate = self;
    picker.allowsEditing = YES;

    if ((UIButton *)sender == selectPhoto)  {

        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
    else {
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    }

    [self presentModalViewController:picker animated:YES];
}

-(void)imagePickController:(UIImagePickerController *)picked didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [picked dismissModalViewControllerAnimated:YES];
    NSLog(@"Geselecteerd: %@", [info objectForKey:UIImagePickerControllerEditedImage]);
    //photo = [[UIImageView alloc] init];
    [photo setImage:[info objectForKey:UIImagePickerControllerEditedImage]];
}

@end

因此,我的相册或相机已正确加载/激活,但是当我单击“使用”或照片时,在视图关闭后我只看到 2 个按钮和一个空的 UIImageView。 'photo' 连接到 UIImageView,'selectPhoto' 和 'takePhoto' 连接到它们的按钮,'selectPicture' 连接到两个按钮'Touch Up Inside-action。 谁能帮帮我?

【问题讨论】:

    标签: iphone objective-c xcode camera xcode4


    【解决方案1】:

    您的委托方法中有错字。

    应该是

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

    但你有

    - (void)imagePickController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    

    【讨论】:

    • 我不知道是该给自己买些新眼镜,还是直接上床睡觉。谢谢队友(不知何故,10分钟后可以接受答案)
    • 你比我早了大约 50 秒。所以避免重复的答案并投票给你的答案
    • :谢谢。发现别人的错字是开始新一天的好方法。我敢肯定,到最后我会沉浸在自己的错误代码中。
    • 或许等我再次醒来,我可以报恩;)
    【解决方案2】:
    - (void)viewDidLoad
    {
    [super viewDidLoad];
    listLocations = [[NSMutableDictionary alloc] init];
    listDevices = [[NSMutableDictionary alloc] init];
    picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    }
    

    【讨论】:

    • 只需将您的 viewDidLoad 替换为这个。设置picker.delegate = self;所以它会调用它的委托方法 didFinishPickingMediaWithInfo 调用
    猜你喜欢
    • 2021-01-27
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多