1

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. 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.

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.

Community
  • 1
  • 1
roro
  • 265
  • 3
  • 11
  • First, if you're using a storyboard, you should be alloc init'ing WorkspaceViewController. That's not the way to instantiate a view controller from a storyboard. Do you have any segues hooked up in the storyboard? – rdelmar Apr 28 '13 at 05:37
  • Does this problem occur because you tap rapidly the button nextView more than one? – user523234 Apr 28 '13 at 09:22
  • rdelmar, no I have not used segues yet. Feel free to point me in the right direction. user523234 This happens upon the first call of next view (it's called from a notification observer). Thanks all. – roro Apr 28 '13 at 21:43
  • rdelmar, did you meant I should NOT be alloc init'ing WorkspaceViewController? – roro Apr 28 '13 at 21:56
  • I see that I can perhaps use [self performSegueWithIdentifier:toWorkspace sender:<#(id)#>]; Then I can click the segue in the storyboard connecting V1 to V2, and in the storyboard editor I can name that segue's identifier "toWorkspace". But the above method still says "Use of undeclared identifier 'toWorkspace'. Do I have to import the storyboard and if so how? – roro Apr 28 '13 at 22:15

3 Answers3

2

Did you create a segue from the button to your WorkSpaceViewController? If so, you are likely attempting to present the WorkSpaceView twice - once when the button is selected and once from 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. That should take care of it.

B-Rad
  • 353
  • 3
  • 11
2
- (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];
                         }];
}
Atanu Mondal
  • 1,714
  • 1
  • 24
  • 30
0

try

[self presentModalViewController:workspace animated:YES];
if (![[self modalViewController] isBeingPresented]) {
      [self dismissModalViewControllerAnimated:YES];
}
Dominic
  • 351
  • 4
  • 18