autresphere / ASDepthModal

An Objective-C class that adds a sense of depth to your modal popup views.
MIT License
430 stars 74 forks source link

The background view is the root view controller not the viewcontroller from where I started the action #13

Open sophyandres opened 11 years ago

sophyandres commented 11 years ago

Hi, I encountered an issue when trying to implement this in my app. The background view is the root view controller not the viewcontroller from where I started the action, and when I close the popup it redirects to the root view controller of the application. Can you help?

Mewnatica commented 11 years ago

I had the same problem. My solution for now was to modify presentView so I can send along the current viewController among the parameters. Then, in the same method, instead of self.rootViewController = window.rootViewController; I set self.rootViewController = viewController; Where viewController is the current viewController. Seems to work just fine... Another catch though; if your "current" viewController is not the rootController (as it seems to be the case), chances are dismissing the popup will set your current viewController as the rootController. You may need to adapt to this situation also, maybe change a bit the way the popup is presented and dismissed. But I guess this is not an issue in current recommended application flow.

jonasman commented 11 years ago

My solution is way simpler:

if (window.rootViewController.presentedViewController) self.rootViewController = window.rootViewController.presentedViewController; else self.rootViewController = window.rootViewController;

What do you think?

jonasman commented 11 years ago

Ok my solution doesnt work very well... the rootVC is deallocated . There is a need to keep it in memory still to go back

My issue is when i show a popup from a modal VC.

Mewnatica commented 11 years ago

It certainly might be a good idea to get the presented view controller like that instead of passing it along like a parameter. If it works, then go for it. But yes, there is a problem when you try to dismiss the popup. I finally skipped messing with the rootVC altogether. So I set self.rootViewController as the current presented view controller, commented the line: //window.rootViewController = self The problem with this is that you lose the reference to the popup view when you try dismiss it, as it is not the rootViewController anymore. But the popup view should be the one on top of the stack. So I changed the dismiss methods to this:

It's convoluted but it works for me, as I'm stuck with a project with no storyboards nor any of the new fancy ways to navigate through views...

jonasman commented 11 years ago

The issue is that ASDepthmodal should be presented from our vc and not added as the root VC. Then when dismissed it would return to the previous VC without any problem.

This would involve a little of architecture change to the whole class.