将照片保存到UIImageView

时间:2013-02-14 02:10:45

标签: ios cocoa-touch

应用程序应该拍摄/选择图片然后将其分配给图像视图。一切似乎都有效,但图像视图永远不会改变。我的代码:

- (IBAction)takePicture:(id)sender
{
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
// Lazily allocate image picker controller
if (!imagePickerController) {
    imagePickerController = [[UIImagePickerController alloc] init];

    // If our device has a camera, we want to take a picture, otherwise, we just pick from
    // photo library
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
    {
        [imagePickerController setSourceType:UIImagePickerControllerSourceTypeCamera];
    }else
    {
        [imagePickerController setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
    }
}
// Place image picker on the screen
[self presentViewController:imagePickerController animated:YES completion:nil];

}


-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    [self dismissViewControllerAnimated:YES completion:nil];
} else {
    [imagePickerPopover dismissPopoverAnimated:YES];
    imagePickerPopover = nil;
}

UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

[imageView setImage:image];
  }

2 个答案:

答案 0 :(得分:0)

你需要一个代表。添加:

imagePickerController.delegate = self;

答案 1 :(得分:0)

在我看来,您没有为图像选择器设置委托,例如:[imagePickerController setDelegate:self];我认为这将在您的takePicture方法中。