0

I have three view controllers, say A, B and C. I am navigating through this views like follows;

A -presenting-> B -presenting-> C -presenting-> B

And from B, if I dismiss I want to navigate to C. But instead of that, now it is moving to A. I can't use dismiss for navigation from C to B (some internal issues). So how can I fix this? Please help.

Mithuzz
  • 1,091
  • 14
  • 43

2 Answers2

1

You hit into a limitation of dismissModalViewController: it will remove all of your modal views (source):

If you present several view controllers in succession, and thus build a stack of presented view controllers, calling this method on a view controller lower in the stack dismisses its immediate child view controller and all view controllers above that child on the stack. When this happens, only the top-most view is dismissed in an animated fashion; any intermediate view controllers are simply removed from the stack. The top-most view is dismissed using its modal transition style, which may differ from the styles used by other view controllers lower in the stack.

What you could do is using a UINavigationController and simply push/pop controllers on to it according to your requirements.

Alternatively, you could simply display the views managed by the various controllers you have by directly calling addSubview on your top view and making sure they cover the whole screen and that the managing controller is correctly retained/released (the view is automatically when you add/remove it to another view).

As a hint, you could do it like this:

  1. where you have presentModal..., use addSubview;

  2. where you have dismiss..., use removeFromSuperview;

  3. store a reference to any view controller whose view you manage like I suggest here in retain/strong property.

sergio
  • 68,819
  • 11
  • 102
  • 123
  • I can't use navigation controller in this one. I have to use presenting and dismissing methods. – Mithuzz Jul 24 '12 at 08:48
  • please, see my edit. in your case, the only way I see is manually doing `addSubview`/`removeFromSuperview` with your "modal" views. – sergio Jul 24 '12 at 08:51
  • I appreciate your help but now I can't use the above suggestion in my app right now, as I have almost completed all the works and few are remaining and got this error. – Mithuzz Jul 24 '12 at 09:08
  • is there any way, if I keep an object of a parent viewcontroller and dismissing the view? I am not sure how to do this, but it just came up in my mind. Any idea? – Mithuzz Jul 24 '12 at 09:30
  • I don't think you have any easy way to use modal view controllers. On the other hand, using addSubview/removeFromSuperview should be really straightforward and requires no big changes to your app. – sergio Jul 24 '12 at 15:57
0

Hi use the below code in "C" viewcontroller

[[[self presentingViewController] presentingViewController] dismissModalViewControllerAnimated:YES];