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
Related
I'm doing a storyboard segue when tapping a navigation bar button item, from view controller A to view controller B, and it works fine with a push animation. But when I tap the back button (no custom code) the previous view (A) just pops into place without the sliding animation. The same happens when I do a [self.navigationController popViewControllerAnimated:YES], i.e. there's no animation. I've made sure that I'm only popping it once.
This has been tested in the simulator as well as on a device.
I suspect it has something to do with what happens when view controller B is being unloaded or something similar, but I can't put my finger on it. I am handling an ABRecordRef property in B, but I have tried to be careful to call CFRetain and CFRelease in the setter when appropriate. I'm doing calls to outlets in various setters and getters but again have been careful to only do it if the view is loaded in case that would cause the view to reload after being unloaded. No success.
Finally did a log in B's viewWillDisappear, and animated is set to false. Why's that?
I don't know what to do next, my segue has the "push" style in the storyboard.
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.
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.
I'm developing a project in objective-c for ios, and I have a view with multiple tabs using a subclass of UITabBarController. Each tab has it's own UINavigationController. When a view loads on a tab, the appropriate activation events fire (viewWillAppear, viewDidLoad, etc.). However, once you tap on a different tab, and tap back, not all these events will fire again since the view is already the visible view for that specific tab (viewDidLoad for example).
My question is this: is there a notification or delegate that I can simply register for and get notified when the visible view in the window changes? I've done some research and I didn't find anything specific for this. What I plan on doing is:
Check the visible view when the tab bar index changes: tabBarController:didSelectViewController
Register for this event on each navigation controller: navigationController:didShowViewController:animated:
By doing this, I should be notified whenever the visibleViewController changes by either changing the tab, or navigating within the tab's navigation flow (except for modals, in this case, I don't care about them. They are handled already).
Is this the right approach?
Have you looked at UITabBarControllerDelegate? This method sounds what you are looking for:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
From the documentation:
In iOS v3.0 and later, the tab bar controller calls this method regardless
of whether the selected view controller changed. In addition, it is called only
in response to user taps in the tab bar and is not called when your code
changes the tab bar contents programmatically.
Here's the link: http://developer.apple.com/library/ios/#documentation/uikit/reference/UITabBarControllerDelegate_Protocol/Reference/Reference.html
Hope that helps!
First implement the UITabBarController delegate method "tabBarController:didSelectViewController" and register for it in the app delegate. You can't register for it in each navigation controller. Only one object can be the delegate. In that method, typecast it to a UINavigationController.
Then get the UIViewController by calling "topViewController" on that UINavigationController. Then call the viewWillAppear: method directly on it.
I have a CustomTabBar created working as expected. Apart from selecting tabs, I want to perform an action (refresh some info) on one of my viewcontrollers when this tab is already selected. I mean, I have a tab selected and I press that tab again and fire an action of the ViewController.
Any suggestion?
If your custom tab bar controller is a subclass of UITabBarController then you can provide a delegate that responds to tabBarController:didSelectViewController:. In iOS 3.0 or later this will still fire if the view controller is the same as the one already selected, so you can track this and send your update messages to the correct view controller in this case.
If you don't subclass UITabBarController and have written the tab bar changing code yourself, then implementing a delegate protocol and sending notifications of tab changes and other events is probably a good idea.