0

There are a lot of stuff on the net according the topic but I don't get it. I have an App with Custom segue implementation and without Navigation controller. There are cases in which I need to unwind back several steps.

For implementation I use simple calls:

CODE CUSTOM SEGUE

For wind:

[[self sourceViewController] presentModalViewController:[self destinationViewController] animated:YES];

For unwind:

[[self destinationViewController] dismissViewControllerAnimated: YES completion: nil];

As I understand when I wind segue somewhere in the memory there is data which is used during the unwind. For that reason in the custom unwind I only use read only property destinationViewController.

So how can I unwind several steps back in one action? Or I have to make several unwinds in different View controllers?

I read the following question, but I don't understand implementation.

Bellow I put example of my apps logic:

EXAMPLE

I have 4 VC which is in a chain: VC A -> VC B -> VC C -> VC D

I wind and unwind back and forth. The logic is ok. There are situation in which I need to unwind back from VC D to VC B. How to do that? Can I unwind directly to VC B or I have to unwind to VC C and then in the unwind handler to unwind to VC B?

I also thought of additional segue from VC D to VC B, but there are remarks on the net that this is not the right way, because segue chain will get messy.

Community
  • 1
  • 1
new2ios
  • 1,350
  • 2
  • 25
  • 56

2 Answers2

1

The answer to What are Unwind segues for and how do you use them? has everything you need to know about unwindSegues (I suggest you re-read it).

But for a more direct answer, yes you can unwind back from VC D to VC B. To do that you have to first implement the method in VC B:

 - (IBAction)unwindToVCB:(UIStoryboardSegue *)unwindSegue
{
}

after doing so, go to the IB, and control-drag a button's action to the Exit icon, you should then pick the method you created above as the selector. (This is taken directly from the question/answer stated above).

Again, for a clearer version of what I said, read the answer of the linked question I mentioned above.

Community
  • 1
  • 1
RJiryes
  • 951
  • 10
  • 25
  • 10x, I think I now understand. I forgot that unwind is implemented in the 1st controller - to which I have to unwind. I will try that at once. 10x again. – new2ios Nov 03 '14 at 09:53
  • Of course @RJiryes. Actually I've read that answer, but did not figure out that `unwindtoVCB` must be implemented in VC **B**. – new2ios Nov 03 '14 at 09:55
  • Yes, I thought so, thats why I put it in terms of your question. Good luck. – RJiryes Nov 03 '14 at 09:56
1

You have to use UINavigationController, just add it in storyboard as mainViewController and set 'A' ViewController as root view controller for it, then change all segues to push segue, set 'Identifires' for them, and you can use performSegueWithIdentifire to push view controller and inside view controller:

[self.navigationController popViewControllerAnimated:];

or

[self.navigationController popToViewController: animated:];

to dismiss it.

mityaika07
  • 652
  • 5
  • 14
  • I do not use `UINavigationController` @mityaika07. I have problem with the design and I don't know how to hide `Navigation controller` - it must be invisible on my UI. Also the answer of @RJiryes works. – new2ios Nov 03 '14 at 10:07
  • [self.navigationController setNavigationBarHidden:self.panelsHidden animated:YES]; can be used to hide top bar – mityaika07 Nov 03 '14 at 10:14
  • 10x @mityaika07. I will take that into account. But I will not use it now, because I already have my navigation logic. – new2ios Nov 03 '14 at 10:33
  • most problem in you case: that modalViewControllers have problems with rotations, I suggest to read this one: http://stackoverflow.com/questions/3772016/modal-view-controller-wont-start-in-landscape-mode – mityaika07 Nov 03 '14 at 10:39