I have a view hierarchy like this:
- A custom view controller (Say view controller 1) shown from app delegate.
- Another view controller (Say view controller 2) shown modally from view controller 1.
- Another view controller (Say view controller 3) shown modally from view controller 2.
- 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.
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.
精彩评论