首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >UIimagepickercontroller

UIimagepickercontroller
EN

Stack Overflow用户
提问于 2011-12-07 14:01:56
回答 1查看 1.3K关注 0票数 1

我正在使用UIimagepickercontroller浏览或拍摄照片,并将其显示在子视图上。

代码语言:javascript
运行
复制
-(IBAction) getPhoto:(id) sender {

    secondView1 = [[secondView alloc] 
               initWithNibName:@"secondView"
               bundle:nil];
    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;

    if((UIButton *) sender == choosePhotoBtn) {
        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    } else {
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    }

    [self presentModalViewController:picker animated:YES];    
    [self.view addSubview:secondView1.view];
}

这在SourceTypeSavedPhotoAlbum上运行良好,但如果我使用相机,则不会显示secudview1.view。相反,它只显示原始视图。

这是我的委托方法:

代码语言:javascript
运行
复制
- (void)imagePickerController:(UIImagePickerController *)picker  
        didFinishPickingMediaWithInfo:(NSDictionary *)info {
    secondView1.imageView.image = [info
    objectForKey:@"UIImagePickerControllerOriginalImage"];
    [[picker parentViewController] dismissModalViewControllerAnimated:YES];
    [picker release];
}

谢谢你的帮助!

EN

回答 1

Stack Overflow用户

发布于 2011-12-12 10:37:06

我终于发现我应该这样做:

代码语言:javascript
运行
复制
secondView1 = [[secondView alloc] 
    initWithNibName:@"secondView"
    bundle:nil];
self.view addSubview:secondView1.view];

在委托函数中。

代码语言:javascript
运行
复制
(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    ...
}

否则,可能会在图像拾取器完成图像拾取之前调用addsubview。现在更好地了解代码流和委托的功能。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8411060

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档