[英]Simple view controller switch causes: Attempt to present while a presentation is in progress
I am learning how to handle view controller hierarchies using the storyboard. 我正在学习如何使用故事板处理视图控制器层次结构。 I have 2 ViewControllers: the root of type cwViewController (what I understand is 'self' below) and a second of type WorkspaceViewController.
我有2个ViewControllers:类型为cwViewController的根(我理解的是下面的'self')和第二个类型的WorkspaceViewController。 I am getting "Attempt to present while a presentation is in progress!"
我正在“在演示文稿正在进行时尝试演示!” as a result of this code.
作为此代码的结果。
- (IBAction)nextView {
WorkspaceViewController *workspace = [[WorkspaceViewController alloc] initWithNibName:nil bundle:nil];
[self presentViewController:workspace animated:YES completion:NULL]; }
The answer to How to present view controller properly? 如何正确呈现视图控制器的答案? is the closest answer that could apply but doesn't quite fit this scenario because I'm not switching back and forth between VCs, I'm just presenting one, then dismissing it to display the original.
是最接近的答案可以应用,但不太适合这种情况,因为我不是在VC之间来回切换,我只是提出一个,然后解雇它来显示原始。
Then, I tried dismissing the current one before presenting the second, as some answers suggested, like this: 然后,我尝试在呈现第二个之前解除当前的一个,正如一些答案所示,如下所示:
[self dismissViewControllerAnimated:NO completion:nil];
[self presentViewController:workspace animated:YES completion:NULL];
But that just gets me an additional Warning: Attempt to dismiss from view controller while a presentation or dismiss is in progress! 但这只是给我一个额外的警告:在演示或解雇过程中尝试从视图控制器中解雇!
Doing some other research I saw similar problems were solved by adding a block to 做了一些其他的研究我看到类似的问题通过添加一个块来解决
[self dismissViewControllerAnimated:YES...]
But that doesn't help here because my warning occurs before I even get to a point where I call that dismiss method. 但这在这里没有帮助,因为我的警告发生在我甚至到达我称之为解雇方法的点之前。 Any further knowledge on how the order and hierarchy of views are meant to be handled would be a big help.
有关如何处理视图的顺序和层次结构的任何进一步知识将是一个很大的帮助。 Thanks very much.
非常感谢。
Did you create a segue from the button to your WorkSpaceViewController? 你是否从按钮创建了一个segue到你的WorkSpaceViewController? If so, you are likely attempting to present the WorkSpaceView twice - once when the button is selected and once from cwViewController.
如果是这样,您可能会尝试两次呈现WorkSpaceView - 一次选择按钮时,一次来自cwViewController。 To eliminate the error, delete the segue from the button to WorkSpaceViewController and then recreate the segue - this time between cwViewController and the WorkSpaceViewController.
要消除错误,请将按钮中的segue删除到WorkSpaceViewController,然后重新创建segue - 这次是在cwViewController和WorkSpaceViewController之间。 That should take care of it.
那应该照顾它。
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// TODO: make this all threaded?
// crop the image to the bounds provided
img = [info objectForKey:UIImagePickerControllerOriginalImage];
NSLog(@"orig image size: %@", [[NSValue valueWithCGSize:img.size] description]);
// save the image, only if it's a newly taken image:
if ([picker sourceType] == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum(img, nil, nil, nil);
}
// self.image_View.image = img;
// self.image_View.contentMode = UIViewContentModeScaleAspectFit;
NSLog(@"Picker has returned");
[self dismissViewControllerAnimated:YES
completion:^{
ModalViewController *sampleView = [[ModalViewController alloc] init];
[self presentModalViewController:sampleView animated:YES];
}];
}
try 尝试
[self presentModalViewController:workspace animated:YES];
if (![[self modalViewController] isBeingPresented]) {
[self dismissModalViewControllerAnimated:YES];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.