0

I've browsed the different similar questions here but couldn't find anything useful for my problem. What I'm struggling with is quite simple but I can't figure it out.

I'm using Xcode 4.6.2 and Storyboarding. Here is the storyboard: enter image description here

Here is the workflow I'd like to have:

  • Taping on a cell in the tableVC should push the Edit document view and offer the Back and Done buttons.
  • Taping on the camera picture should "load" (push/modal?) my cameraVC which is a subclass of UIImagePickerController. I've added a custom overlay on top of the picker and use a custom button to take picture. On this event I currently perform the segue leading to the previewDocumentView (modally presented) and when the "Use" button is tapped I present the Edit document view.

Problem is the Edit document view does not have the navigation bar even if I try to set the property self.navigationBarHidden = NO; This seems normal to me though since I've presented the views modally but how to do it then?

I tried pushing my cameraVC from the tableVC but I get an error saying that stacking 2 navigationControllers is prohibited (since cameraVC subclass of UIImagePickerController subclass of UINavigationController). It seems that my only option is to present the cameraVC modally but then I don't know how to present the Edit document VC with its navigation bar.

EDIT: Having a navigation bar in the cameraVC is not optimal but is acceptable if this is the only way of doing it.

Bonnie
  • 4,943
  • 30
  • 34
Anth0
  • 3,004
  • 6
  • 26
  • 36
  • why dont you dismiss the cameraVC and then Push the EditDocumentView, this way you will have the NavigationBar you need. – Bonnie May 13 '13 at 08:38
  • You could try embedding the camera view controller in a navigation view controller, and setting the navigation bar to hidden. Then, when you go to the edit document view from the camera view, you can unhide the navigation bar. – rickerbh May 13 '13 at 08:47
  • @Bonnie because I need the previewDocumentVC between cameraVC and editDocVC. This view is necessary for the user to confirm or dismiss the use of the picture he's taken. Moreover, is there a way to be somehow notified when the cameraVC would be dismissed to tell the listDocumentsVC to push the view? I already tried something like this self dismissViewControllerAnimated:NO completion:^{ [self performSegueWithIdentifier:kPreviewSegue sender:doc]; }]; but I end up on the listDocumentsVC with a warning Attempt to present xx on yy whose view is not in the window hierarchy! – Anth0 May 13 '13 at 08:51
  • @rickerbh cameraVC is a subclass of UIImagePickerController which is already a subclass of UINavigationController. Is it possible to do so? – Anth0 May 13 '13 at 08:55

1 Answers1

1

It would appear that the best solution is to use an unwind segue!

In summary:

1)In the tableVC create a method such as

- (IBAction)unwindToThisViewController:(UIStoryboardSegue *)unwindSegue
{
    NSLog(@"Rolled back");
}

2)Create an unwind segue for your previewDocumentVC and give it a unique ID such as "unwindFromPreview", connecting it to the unwindToThisViewController IBAction. Check this answer I gave in the past for the detailed steps on how to achieve this (steps 2 and 3).

3)Create a prepareForSegue method in your previewDocumentVC where you set some tableVC BOOL property, such as

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"unwindFromPreview"]) {
        ((TableVC*)segue.destinationViewController).shouldTransitionToEditDocVC = YES;
    }
}

4) In your tableVC's ViewWillAppear method you then check the shouldTransitionToEditDocVC and if it is set to YES you perform the segue to the editDocVC.

I hope this helps!

Community
  • 1
  • 1
micantox
  • 5,446
  • 2
  • 23
  • 27
  • Ok but how should I load my listDocsVC from previewDocVC? If a do a modal transition then I don't have my nav bar neither. Pushing it generates me an error like this "Push segues can only be used when the source controller is managed by an instance of UINavigationController." – Anth0 May 13 '13 at 09:26
  • 1
    I re-edited my answer, this time it should be the proper way to go! – micantox May 13 '13 at 10:44
  • Thank you very much for this! I didn't know about unwind segue at all. This is exactly what I was looking for and it works almost like a charm. The only glitchy part is that I can't perform a segue in viewWillAppear without messing my navigation bar. I had to move the code in viewDidAppear but then, of course, the tableVC is quickly displayed before transiting to editDocVC. Any way to get around this? It would be the icing on the cake. In any cases, I'm already satisfied by your answer and will mark it as resolved right away :) – Anth0 May 13 '13 at 11:44
  • I tried to do it in a test project and it doesn't mess the navigation bar, what kind of error do you get if you do it in the viewWillAppear method? – micantox May 13 '13 at 13:11
  • I get "nested push animation can result in corrupted navigation bar" and "Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted." Here is picture of what it looks like : http://cubeupload.com/im/lEWR2c.png. As you can see the title is messed up and the back button is incorrect. It should point to "Documents". When I press it I go back to the tableVC with also a messed up title and another back button named "Documents". Tapping on this one brings me back on a correct tableVC. So it's like it's being pushed twice and and bar doesn't like it. – Anth0 May 13 '13 at 13:22
  • hum just noticed something weird in the log too, I log a rolled back message in the unwind action and I just found two outputs for one tap on the button: 2013-05-13 15:17:03.661 Scan[7034:907] Rolled back from 2013-05-13 15:17:03.707 Scan[7034:907] Rolled back from – Anth0 May 13 '13 at 13:26
  • 1
    This last problem looks like it's caused for performing the unwind segue twice. If you created it by dragging from the button itself to the exit box, then you don't need to execute the performSegue manually in the code! – micantox May 13 '13 at 13:29
  • oh my... I feel so stupid about this one. This was the cause of the problem. Everything is working perfectly now. Thanks a lot again! – Anth0 May 13 '13 at 13:38