【发布时间】:2011-06-27 14:35:38
【问题描述】:
我试图在我的 UIImagePickerController 的委托函数返回“didFinishPickingImage”后立即打开一个新视图 (UnprocessedPhotoViewController)。
不幸的是,我似乎可以打开 UIImagePickerController 模态视图,或者切换到 UnprocessedPhotoViewController 作为模态视图,但不能同时按顺序进行。
在下面的代码中,按下按钮会激活 pickPhoto IBAction。此代码成功激活 UIImagePickerController。用户选择图像后,调用 didFinishPickingImage 委托函数,将图像存储到变量中,尝试关闭 UIImagePickerController 模态并在新模态中打开 UnprocessedPhotoViewController。
注意:如果我注释掉 ImagePicker 并直接运行“showPhoto”,UnprocessedPhotoViewController 显示成功。此外,如果我创建一个新按钮来启动任一视图,它会成功运行,但我无法按顺序启动视图。我希望在用户选择图像后,将启动新视图,允许用户处理图像。
保证 ImagePicker modal 关闭然后打开 UnprocessedPhotoViewController 的正确方法是什么?
谢谢!!!
代码:
- (IBAction)pickPhoto:(id)sender{
//TODO: To be replaced with the gallery control launching code
// Load Image Selection Code
self.imgPicker = [[UIImagePickerController alloc] init];
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:self.imgPicker animated:YES];
}
// Dummy function assumes you either picked (or took a picture =D) of Angie and moves you right to the unprocessed viewing screen.
- (void) showPhoto{
// Start new view controller
[self dismissModalViewControllerAnimated:YES];
UnprocessedPhotoViewController *upViewController = [[UnprocessedPhotoViewController alloc] initWithNibName:@"UnprocessedPhotoViewController" bundle:nil];
upViewController.imageView.image = selectedImage;
upViewController.delegate = self;
upViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:[upViewController animated:YES]];
[upViewController release];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img {
selectedImage = img;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
[self dismissModalViewControllerAnimated:YES];
[self showPhoto];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
【问题讨论】:
标签: iphone uiviewcontroller uiimagepickercontroller