“imagePickerController:didFinishPickingMediaWithInfo:”的问题

时间:2011-06-18 14:16:59

标签: ios objective-c xcode

我一直收到一个未使用的变量警告。我正在尝试显示模式视图,用户选择照片,我想在UIImageView中使用所选图像。

不确定这是否足够,但我真的很感激任何帮助。

- (IBAction) buttonPressed:(UIButton *)sender { 
    UIImagePickerController *picker = [[UIImagePickerController alloc] init]; 
    picker.delegate = self;
    [self presentModalViewController:picker animated:YES];
    [picker release];
}

- (void) imagePickerController:( UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info { 
    UIImage *image = [info objectForKey: UIImagePickerControllerOriginalImage];
}

1 个答案:

答案 0 :(得分:2)

您收到警告,因为您不再使用图片对象了。您必须将此图像保存在某个类对象中以在代码中的某处使用它,如果您这样做,警告将自动消失。或者只是删除你可以做的警告:

-(void) imagePickerController:( UIImagePickerController *)picker didFinishPickingMediaWithInfo: (NSDictionary *)info {  
 UIImage *image;  
 image=[info objectForKey: UIImagePickerControllerOriginalImage];   
}