0

Here is my storyboard configuration:

Navigation Controller -> View Controller A -> Push-> View Controller B
^
|
Modal
^
|
View Controller C

What I want to achieve: When a button is pressed in View C, directly View B will be opened modally (No part of View A is to be displayed). Also, View B will have a navigation back button to View A.

To achieve this,

  • I set up the illustrated storyboard.
  • I created a segue between View C and the Navigation Controller of View A/B.
  • In the 'prepareForSegue' method of View Controller C, I get an instance of View Controller A as the first element in the navigation. In this instance, I set a variable like 'directlyProceedToViewB=YES'.
  • In the viewDidLoad method of View Controller A, I check the variable 'directlyProceedToViewB' and if it is YES, I call 'performSegueWithIdentifier' to segue to View B

The result is so that, first View A is opened modally and after displaying it a very short time, View B is opened with a push animation (View B can navigate back to View A, which is good). But I do not want View A to be displayed any time at all. How can I achieve this?

EDIT:

To better visualize, I'm adding a screenshot with more example cases to support:

enter image description here

Here are some cases I want to support:

  • We can start with ViewC, click on 'Modally Display B' which opens ViewB, then click 'Back to A' to navigate back to ViewA, then click on 'Dismiss Modal' on ViewA to go back to ViewC
  • We can start with ViewD, clcik on 'Modally Display A' which opens ViewA, then click on 'PushB' to open ViewB, then go back and forth between A and B and modally dismiss to ViewD.
ali gurbuz
  • 180
  • 1
  • 2
  • 13
  • Rather to perform segue from viewA to viewB. Simply have a segue between viewC and viewB. Also you could set no to animation. – nikhil84 Sep 30 '14 at 09:08
  • But in that case, I wouldn't have a back navigation from viewB to ViewA, would I? – ali gurbuz Sep 30 '14 at 09:12
  • It would be almost impossible to help unless you please INCLUDE AN IMAGE of your storyboard, showing your goal. – Fattie Sep 30 '14 at 09:34
  • It's possible you need t simply use container views for this. http://stackoverflow.com/a/23403979/294884 – Fattie Sep 30 '14 at 09:35
  • 1
    create a segue between View C and View B and on a button click in C call method performseguewithIdentifier why are you complicating this so much??? – Rohit Sep 30 '14 at 09:39
  • @Rohit Then once the View B is opened, how will I be able to navigate back to View A? – ali gurbuz Sep 30 '14 at 09:42
  • @aligurbuz it would work normally as stack will have your recent on top(viewB) and previous at bottom(viewA) ,and for viewC it's just present and dismiss. If user jumps directly to viewC and then to viewB in that case it might not show viewA. Still you could try this out. – nikhil84 Sep 30 '14 at 09:50
  • @walle84 I have edited and added example scenarios and yes, the user can start from ViewC. In that case, performing segue from C to B does not allow to navigate back from B to A. – ali gurbuz Sep 30 '14 at 10:11
  • @JoeBlow I have added images of my storyboard – ali gurbuz Sep 30 '14 at 10:13
  • @aligurbuz once for navigating back to view A once View B is opened you can create a segue between the both and call them whenever you want to navigate. – Rohit Sep 30 '14 at 10:18
  • @Rohit I would prefer to avoid it as it would complicate my design. Imagine ViewB like a detail view of ViewA. For example, ViewA is a table view, and ViewB is a view corresponding to clicking on one of the table cells. – ali gurbuz Sep 30 '14 at 10:21

4 Answers4

2

First of all, some corrections: those are not views but view controllers. And "view A" is not pushed into the UINavigationController but it's the root.

After that, I suggest making the segue in "view C" an unwind segue and implement the IBAction in "view A" by pushing "view B" with [[self navigationController] pushViewController:bViewController animated:NO].

EDIT (adding some details):

I assume that in ViewControllerA's viewWillAppear you present ViewControllerC in a not animated manner.
Implement an unwinding action like (IBAction)unwindAndThenGoToB:(UIStoryboardSegue *)segue in ViewControllerA.
In the storyboard connect the button in ViewControllerC to the Exit icon and select the previously defined method.
Then implement the method with the push call I wrote earlier.
ps: for documentation there is plenty on Apple's website.

DeFrenZ
  • 2,068
  • 1
  • 20
  • 19
  • Try to see if it's better now. – DeFrenZ Sep 30 '14 at 09:32
  • I'm not presenting VC_C from VC_A. That's not path I'm concerned. The paths I want to achieve are: VC_C -> VC_B modally with a possibility to VC_B to VC_A as a back navigation. And after VC_A is opened from VC_B, it may go to VC_B again with normal navigation or modally back VC_C. – ali gurbuz Sep 30 '14 at 09:38
  • The sources I checked for 'unwind segues' describe it as a back navigation. In this case, my path of VC_C -> VC_A (invisibly) -> VC_B is a forward navigation path. Can the 'unwind segues' still be used? – ali gurbuz Sep 30 '14 at 09:39
0

Implement this using delegates.Decalre protocol in which class you want and define those methods and call the methods in the view controller you want.There is no many ways of calling some view and showing back button to go different view.modal view is just a concept.and you can use delegate methods to call whatever class you want.

iOSdev
  • 553
  • 5
  • 22
0

Here I got a way to do so:-

You need to set no animation for segue from viewC to viewA as shown in below image. Then set a segue identifier for segue from viewA to viewB namely, "viewB" and in your viewA .m file add following code,

- (void)viewDidLoad {
  [super viewDidLoad];
  // Place your conditional check here.
  [self performSegueWithIdentifier:@"viewB" sender:self];  //Will directly lead to viewB and viewA won't be shown as no animation is there from viewC to viewA.
}

And your rest flow be like-wise.

No animation for transition from viewC to viewB

nikhil84
  • 3,217
  • 3
  • 19
  • 40
  • Unfortunately, this doesn't create the effect I want either. I tried it and it still displayed ViewA for a short time before navigating to ViewB, but this time opening ViewA without animation. I want to keep the modal transition animation. But it will look like it is modally opening ViewB from ViewC directly, without displaying any part of ViewA. – ali gurbuz Sep 30 '14 at 11:57
  • For that you need to modallypresent viewB and not viewA but in that case you won't have viewA in stack for back functionality. So you need to re-think about your app flow. – nikhil84 Sep 30 '14 at 12:58
0

I found the solution myself.

First, I discovered that, my original proposal of

In the viewDidLoad method of View Controller A, I check the variable 'directlyProceedToViewB' and if it is YES, I call 'performSegueWithIdentifier' to segue to View B

works as I desired on iOS 7 but does not work on iOS 8.

So the solution is, in the viewDidLoad method of View Controller A, if 'directlyProceedToViewB' is YES, rather than calling performSegueWithIdentifier, use the following code:

ViewControllerB *destVC = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewControllerBStoryboardID"];
[self.navigationController pushViewController:destVC animated:NO];
ali gurbuz
  • 180
  • 1
  • 2
  • 13