0

I have a view hierarchy like this:

  1. A custom view controller (Say view controller 1) shown from app delegate.
  2. Another view controller (Say view controller 2) shown modally from view controller 1.
  3. Another view controller (Say view controller 3) shown modally from view controller 2.
  4. There is one more view controller (Say view controller 4) from which I need to follow step 2 & 3.

Now on some activity I need to cancel the whole modal view hierarchy. So what I am doing is, I am sending a notification on that event from view controller 3 and listeneing to that notification in view controller and then executing:

[[NSNotificationCenter defaultCenter] removeObserver:self name:@"cancelViews" object:nil];

This works but there is one problem. As per my app flow I am ending up registering for this notification at both view controller 1 and view controller 4. Now, when whole modal hierarchy for view controller 1 was up and notification was registered by VC1 and then on top of that another view hierarchy for view controller 4 is shown and finally when notification is thrown both my view hierarchy disappears.

I want only my top most view hierarchy to be disappeared. Any solution for this will really help.

Abhinav
  • 37,684
  • 43
  • 191
  • 309

1 Answers1

1

Use delegates!

If that isn't a route you want to take (even though I strongly encourage you to do so) you can setup your 1 and 4 view controller to publish different events for which your root view controller will listen.

Community
  • 1
  • 1
Wayne Hartman
  • 18,369
  • 7
  • 84
  • 116
  • Due to some technical challenges I did not take the delegate path. What do you mean by different events? If you are talking about different notification name then it wont help as notifications will be dispatched at same place. So, instead of one then I will post 2 notifications. Same place!!! – Abhinav Apr 24 '11 at 04:04
  • Have you looked into UINavigation controller? There might be the solution. – TheBlack May 14 '11 at 03:34