我希望用户在按下按钮时通过iphone选择图像(通过操作:按钮点击),我希望该图像在我拥有的图像视图上查看(imageAddPicture是图像视图的名称)
我发现了很多信息,但是当我使用此代码时,我会收到以下错误:
self,release,picker.sourceType =(sender == buttonClicked),...
有人能帮帮我吗? (我是stackoverflow.com的新手,但我真的需要帮助,我会尽力帮助其他人) 这是我使用的代码:-(IBAction)buttonClicked:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = YES;
picker.sourceType = (sender == buttonClicked) ? UIImagePickerControllerSourceTypeCamera :
UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController: picker animated:YES];
[picker release];
}
-(IBAction)selectExitingPicture
{
if([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *picker= [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
}
-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingImage : (UIImage *)image
editingInfo:(NSDictionary *)editingInfo
{
imageAddPicture.image = image;
[picker dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *) picker
{
[picker dismissModalViewControllerAnimated:YES];
}
答案 0 :(得分:0)
您正在使用自动引用计数来处理项目。所以你不需要释放对象。只需删除此行即可。 Chil:)
picker.sourceType = (sender == buttonClicked) ? UIImagePickerControllerSourceTypeCamera :
UIImagePickerControllerSourceTypeSavedPhotosAlbum;
这一行应该是
picker.sourceType = (sender == buttonClicked:) ? UIImagePickerControllerSourceTypeCamera :
UIImagePickerControllerSourceTypeSavedPhotosAlbum;