Reference to source view controller and destination view controller at the same time?

I think UINavigationControllerDelegate is what you're after. It declares two methods.

Up vote 0 down vote favorite share g+ share fb share tw.

I have a series of UIViewControllers throughout my application. Most of them have the navigation bar but some of them hide it. The problem is that sometimes as you transition between a view with or without navbars to another view with or without navbars there is a black box that replaces the navbar during the transition.

This problem was discussed here: Hiding a UINavigationController's UIToolbar during viewWillDisappear: This solution is fine and it does get rid of the black box, but I really don't want what was described as a "Cheshire Cat" disappearance. I've tried myriad solutions using prepareForSegue, ViewWillAppear, viewWillDisappear, etc. The best I can do is change the scenario in which the black bar shows up. By this I mean, there are four combinations of view transitions between the two navigation bar states (hidden vs. not-hidden): Hidden - Hidden Hidden - Not Hidden Not Hidden - Hidden Not Hidden - Not Hidden No matter what solution I've tried, at least one of those combinations results in my black box rearing its ugly head.

The problem I have is that I've been unable to find anywhere that I can get a reference to the source view controller and the destination view controller when popping a view off of the navigation controller's view stack. If I could get both references in the same event, I could simply determine what the combination is and handle the behavior appropriately like I would in prepare for segue. Now, I know that "it's not possible" is a reasonable (and even a probable) answer, but I won't accept that as a solution alone.

If it is indeed not possible, I'd like thoughts on a reasonable alternative. For example, I could handle all view controller popping manually (including the default back button) and thus could get the "upcoming controller" from the navigation controller's stack. I would just prefer a solution using built in APIs or at least a solution where my controllers didn't have to be aware of their own navigation bar states.

Thanks a lot, Patrick objective-c ios ios5 uinavigationcontroller storyboard link|improve this question asked Jan 24 at 18:04D. Patrick925211.

I think UINavigationControllerDelegate is what you're after. It declares two methods: -navigationController:willShowViewController:animated: -navigationController:didShowViewController:animated: All you need to do is set yourself as the delegate of the parent navigation controller and implement these methods to be notified of incoming view controllers. Having said that, I've never needed to resort to this for hiding and showing navigation bars.

Strictly speaking, view controllers where the navigation bar will always be visible never touch the navigation bar's visibility. When I'm moving into a view controller where it needs to hide, that view controller is responsible for hiding and setting it back to its prior state before disappearing. Following these standards has proven reliable for me.

Mark, when I tried using the UINavigationControllerDelegate, I found that viewController and navigationController. VisibleViewController were always the same. I was hoping this was going to be before the animation so that I would have an opportunity to have both the source and destination at the same time.

You have a good point with regard to each controller setting visibility as it needs. I think that my problem may be in that I'm trying to isolate this logic in one place in a base class. I suppose it wouldn't kill me to have the same two lines of code in every class.

– D. Patrick Jan 24 at 19:39 If you implement -navigationController:willShowViewController:animated: then the view controller passed in is the destination and self is obviously the source. You can implement this in every view controller if necessary.

I don't understand what you're trying to achieve by comparing it to visibleViewController. If you need the functionality to hide and show the bars, just subclass UIViewController to provide that functionality and then subclass that subclass for use in the application. – Mark Adams Jan 24 at 19:42 Oh, that's interesting.

I was setting the delegate in AppDelegate application:didFinishLaunchingWithOptions and letting that delegate last throughout the entire app lifecycle. (note, I really want to hit enter to get line feeds in comments! ) Anyhow, so self is the app delegate, but I could very well change that.

I'm going to try it. – D. Patrick Jan 24 at 19:46 I wouldn't do it that way.

Set each view controller as the navigation controller's delegate as needed and implement the required methods. – Mark Adams Jan 24 at 19:47 I just read your comment again. That's basically what I did Mark.

I subclassed UIViewController and in viewwillAppear, viewWillDisappear, and prepareForSegue, I've tried various things to get rid of the black box and none of them worked all the time. I just tried setting the navigation controller delegate to self in viewWillAppear in the base class. The problem is the new controller's viewWillAppear method gets called before navigationController:willShowViewController so self is still the destination.

– D. Patrick Jan 24 at 19:55.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions