Why isn't my navigation bar controller handling the touchesEnded event on my navigation bar view? - objective-c

This question came closest to describing my problem, but I'm missing something in the general process and the answer eventually goes into "Never mind, I figured out a different solution that isn't described".
In my case, I've got an XIB with a navigation bar and its controller. For the class fields, I've filled in my custom class names. Here's a screenshot showing the XIB, because I think this should be a relatively simple and straightforward setup...
What I want (like in link at the beginning) is for the touchesEnded event to fire so that I can do something. This works for the "view"; I can programmatically write in the event, set a breakpoint, and see that breakpoint get hit. However, my higher-level goal is to push a new view onto the app at that point -- something that I shouldn't do in the view's functionality, and which I can't do anyway because my view doesn't have access to the navigation controller (unless I do some trickery to retrieve the controller, but I want to do this cleanly).
Even though it works programmatically for the view, the touchesEnded event does not get hit for the navigation view's controller. I set it to the delegate, as shown in the image below, which I'm suspecting is perhaps only a part of what I need to do.
So now that I've set the delegate, and have seen that the touchesEnded event is being hit by the view, why isn't my navigation bar view controller picking up on the touchesEnded event? Am I mistaken and should instead be figuring out how to push a new view from the navigation bar's view, since I've seen that THAT touchesEnded event is being hit? It just seems like something I should be handling in the navigation bar view's controller, but I can't get that controller's touchesEnded event hit.
Thanks!

It's not clear from your post, but it looks like you're adding a navigation bar to your app explicitly, is that true? If your controller is embedded in a navigation controller, then there's no need to do that. You can add a view to the navigation bar, and add a UIImage view as a subview. If you set user interaction to be on, and add a tap gesture recognizer to the image view, you should be able to get the effect you want.

Then you have to override UINavigationBar, and override becomeFirstResponder, returning YES.

Related

UINavigationItem Prompt Animation Issue

I have two UITableViewControllers that are connected via a Show segue. The prompt property of UINavigationItem is set on both view controllers in Interface Builder. When the first view controller is shown, the prompt and navigation bar are both displayed properly, however, when performing a segue to the second view controller, the title and the back button animate undesirably. I have tried setting the prompts programmatically in the viewWillLayoutSubviews, viewDidLayoutSubviews, viewDidLoad, viewWillAppear:, and the viewDidAppear: methods of both view controllers, but I get the same effect.
Any ideas on how to resolve this issue? I don't want to resort to a custom view for the titleView because I prefer the stock functionality, but I am not able to figure out how to fix the undesirable animation.
Here is a video if the animation in question.
Well, it looks like this is an issue with the way that the UINavigationItem is laid out when showing the next view controller.
According to Catalina T. in an answer to a similar question, making two calls to set the hidden property of the navigation bar to true and then again to false in viewWillAppear: seems to get by this issue.

Get notified about unsuccessful back swipe gestures in UINavigationController

I have a UINavigationController subclass, which manages a custom navigation bar. This navigation bar's look depends on the top view controller. I ask the top view controller about the type of the bar to be displayed when -pushViewController:animated: or -popViewControllerAnimated: happens.
The problem is, that the navigation bar type change is played when the user starts swiping but I could not find any event which tells me that the swipe was successful or not, so if the user cancels the swipe, I stuck on the previous view controller with the desired navigation bar look of the one below it in the navigation stack.
I have tried UINavigationControllerDelegate, but neither -navigationController:didShowViewController:animated: nor -navigationController:didShowViewController:animated: gets called. My second thought was to use interactiveGestureRecognizer, but it seems it it ends successfully both on successful and cancelled back swipe, and the topViewController is also still the same when the recognizer event is called.
I know, that the top view controller's -viewDidAppear will be called again upon cancelled swipe, but I don't want my users to implement any logic in their controllers to support my navigation implementation.
Any ideas?
Try using the UINavigationControllerDelegate, you can rely on its callbacks to know when a viewController is going to be displayed or not.
Getting interactivePopGestureRecognizer dismiss callback/event

Determine if viewcontroller is already on stack and if so, go to or dismiss it

I have an app I am working on that has a main screen with two buttons. One will take you to a view of a GPS (map) and then once there (new VC) it has options for setting that position or bringing up a list (tableview, another VC) of all locations already tagged.
At the list VC, if you click on the table cell, it will bring up the VC with the map. Problem is, this then adds the same VC bak on the stack. If a user clicks the Cancel button, they go back ones screen, then cancel goes back another screen, etc... until back to the main.
I know I can do the [self.navigationController popToRootViewControllerAnimated:YES]; to pop back to root but that is not always what I want.
Also, I know I can do: [[[self presentingViewController] presentingViewController] dismissModalViewControllerAnimated:YES];
I guess what I am saying is I want to "reuse" the GPS map view so I can call it from other VC's, so that is why I didn't go with the "pass back" to calling VC. So, is there away to either when a button is pressed and is to present a new VC, can I dismiss the prior one after the new one is shown? This way, a dismiss of current VC would take me back to where I need to be.
I hope makes sense and also that this question doesn't fall into the "Not an actual question" category.
Any help or better suggestions is greatly appreciated. Thx
Geo...
If you want to jump back some number of levels in a navigation controller's VC stack, you'll probably want to use its popToViewController:animated: method. To figure out if a particular view controller is on that stack, look at the navigation controller's viewControllers property. Be careful, though, as this kind of jumping around is a rather nonstandard UI behavior (even though there's API for it) which might confuse your users.
Also, using navigation controllers and presenting modally aren't the only ways to manage multiple view controllers -- you can always set the window's rootViewController yourself (and animate the change with UIView animations), even wrapping up your custom transition type in a custom UIStoryboardSegue if you like.
You can put a delegate in the table view. So that when a cell is pressed the info is passed to the delegate method in the VC which will dismiss the table view and reloads itself with the new info. You will have to implement refresh method in that VC.

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

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
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.

Prevent UINavigationController's navigation bar to animate?

My UINavigationController's navigation bar is kind of static. This means, there is no back button, because going back in the stack is done via the first entry of the UITableView the controller holds. The title also always shows the name of the root item.
To achieve this I have added my own custom view to UINavigationController.NavigationItem.titleView
It looks a bit odd if a new controller is pushed in: the old navigation item vanishes, just to get replaced by one looking exactly the same.
Is there a way to prevent this behavior? I want the animation for the content of the controller, so pushing the new controller without animation is not an option.
Add your own UINavigationBar and implement your own delegate and custom animations for the content views.
It sounds like you'll only need one UINavigationItem, so that makes this model easy to manage.