iPhone应用程序中的例外情况:模态转换已在进行中
基于拼凑在一起的一些教程,我认为目前这是一个相当简单的应用程序.我在OSX 10.6.4中使用XCode 3.2.3.它起初是一个标准的iPhone“基于窗口的应用程序”.使用界面构建器我在这里使用O’Reilly视频教程添加了一个Tab Bar Controller:
http://broadcast.oreilly.com/2009/06/tab-bars-and-navigation-bars-t.html 在第一个标签中,我有一个带有两个按钮的标准UIView.两者都调用相同的函数来显示UIImagePickerController: -(IBAction) btnPhotoClicked:(id)sender { UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; imagePicker.delegate = self; if((UIButton *)sender == btnChoosePhoto) { imagePicker.allowsEditing = YES; imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; } else { imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; } [self presentModalViewController:imagePicker animated:YES]; [imagePicker release]; } 我在模拟器中运行代码,所以只需单击“选择照片”按钮.当对话框与所选照片一起发布时,此功能运行: -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { NSURL *mediaUrl; mediaUrl = (NSURL *)[info valueForKey:UIImagePickerControllerMediaURL]; if (mediaUrl == nil) { imagePuzzle = (UIImage *) [info valueForKey:UIImagePickerControllerEditedImage]; if(imagePuzzle == nil) { //--- Original Image was selected --- imagePuzzle = (UIImage *) [info valueForKey:UIImagePickerControllerOriginalImage]; } else { //--- Get the edited image --- //--- If it was successful the above valueForKey:UIImagePickerControllerEditedImage //--- would have assigned it already. } } else { //--- Muppet selected a video } // Animate the picker window going away [picker dismissModalViewControllerAnimated:YES]; ImageViewController *imageViewController = [[ImageViewController alloc] init]; imageViewController.delegate = self; [self presentModalViewController:imageViewController animated:YES]; [imageViewController release]; } 这就是我的问题所在.我尝试了很多不同的黑客和迭代,但上面的代码是最简单的问题.当imageViewController显示为模式对话时,抛出以下异常: 2010-07-09 15:29:29.667 Golovomka[15183:207] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException',reason: 'Attempting to begin a modal transition from <NewViewController: 0x5915f80> to <ImageViewController: 0x594a350> while a transition is already in progress. Wait for viewDidAppear/viewDidDisappear to know the current transition has completed' 我该如何解决这个问题?我尝试过延迟和其他技巧,但是我真的不明白我应该如何使用viewDidAppear或viewDidDisappear来帮助我.另外值得注意的是,一个非常基本的应用程序,其中一个视图加载选择器,然后显示另一个带有图像的视图,不会产生错误.任何帮助感激不尽. 解决方法
要解决此处描述的特定问题,您可以在类中添加viewDidAppear方法:
-(void)viewDidAppear:(BOOL)animated { if (/*just visited ImagePicker*/) { ImageViewController *imageViewController = [[ImageViewController alloc] init]; imageViewController.delegate = self; [self presentModalViewController:imageViewController animated:YES]; [imageViewController release]; } } 从通话下方删除这些行: [picker dismissModalViewControllerAnimated:YES]; 因此,每当你的类出现(显示)时,它将调用viewDidAppear …因为这很可能不是你想要的所有时间,你可以添加一些变量来设置/清除定义是否立即显示self时显示imageViewController.像“如果来自图像选择器,显示imageViewController,否则什么也不做”. 也就是说,imho,推动模态视图通常应该响应用户操作而完成,我可能会在这里重新考虑用户体验 – 例如添加一个子视图,而不是推动你可以在当前拥有代码的地方进行模态视图 – 但是如果你只是在玩一些应该解决NSInternalInconsistencyException的教程. :)干杯! (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |