UINavigationController swipe to go back issue - ios

I am creating NavigationController app which contains login and other pages. I am hiding navigation controller in login page and displaying in other pages. I have back/logout button on the left side of the second screen. when i try to drag from second screen (i am not full swipe to the login screen), navigation bar in second screen becomes hidden. It never appears again on other pages. I need to go back to login and push to second view to make navigation bar to show. When i click back/logout button instead of swipe, it works.
Any idea on solving this issue

In your viewcontroller that you want NavigationBar visible use this code
-(void) viewWillAppear: (BOOL) animated {
[super viewWillApper:animated];
[self.navigationController setNavigationBarHidden:NO];
}

Related

UINavigationController missing from view hierarchy after cancelling UISearchController

I have an app with a UITabBarController and a few tabs, each of which contains a UINavigationController. I also have a UISearchController triggered by a search button on the nav bar, which has a custom search results view controller. Search works just fine, as does tapping cancel. I implemented presentSearchController: to present the search controller as a view controller using
[self presentViewController:animated:completion:];
, which also works fine.
Where I run into trouble is if the user dismisses the keyboard (search controller active), and then switches tabs on the tab bar, comes back to the original tab with search controller active, and then taps "Cancel", the underlying UINavigationController's view stack is gone from the main window hierarchy and doesn't get reloaded until I switch tabs and come back with search mode inactive.
This is similar to this issue: "From View Controller" disappears using UIViewControllerContextTransitioning
Except I don't use any custom transitions, and the tab bar still shows after tapping cancel. Printing the view stack shows the tab bar is the only subview of the window until I switch tabs again and everything displays as normal.
What is the best way to go about solving this? I really hate to brute force re-add the navigation controller's view to the window on didDismissSearchController: as suggested. Not only does this seem like a bad idea, but I also run into issues with the z-ordering of the tab bar and the navigation controller when explicitly re-adding the nav controller to the key window.
Adding my brute-force solution:
- (void)didDismissSearchController:(UISearchController*)searchController
{
if (![self.view isDescendantOfView:[UIApplication sharedApplication].keyWindow]) {
NSUInteger currIndex = self.tabBarController.selectedIndex;
NSUInteger tempIndex = self.tabBarController.selectedIndex == 0 ? 1 : 0;
[self.tabBarController setSelectedIndex:tempIndex];
[self.tabBarController setSelectedIndex:currIndex];
}
}

Strange UINavigationItem behavior after using custom navigation transitioning animations

I am doing a custom UINavigationController pop transition animation.
But having a strange bug, I've made a sample project to demonstrate the issue (Taken from https://github.com/objcio/issue5-view-controller-transitions)
An navigation-based app, 2 view controllers.
The first viewController has 2 bar button items on the navigationBar, a button in the middle of view to push to second viewController.
The second viewController has a left bar button item to pop to the first viewController.
If the second view controller has been dragged less than 50%, my custom animation will cancel the transition, and if it's over 50%, it'll finish the transition, pop the viewController. (Just like the system default)
However, if the transition was cancelled, the navigation item's on the first view controller will be over-ridded.
The "back" item will appear on first view controller, and the right bar button item will disappear.
This is the video to demonstrate: https://youtu.be/qg2lUKsNtzk
And the source code is on github: https://github.com/JohnnyTseng/issue5-view-controller-transitions
Could somebody point out where the problem is? I've been debugging this issue for whole day. Thanks!
In iOS 7 Apple add new default navigation behavior. You can swipe from left border of the screen to go back on navigation stack.
you can stop this by putting this code in application delegate.
if ([self.navigationController respondsToSelector:#selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
you can read more over here interactive pop gesture of navigation view controller

StoryBoard Navigate to Root View Controller

This is my first time using story board and I've set up like 5 view controllers with UINavigationController with buttons that push to the next view controller..
So I start on VC1 and push to VC2, then click and button and push to VC3, then click a button and push to VC4, and so on... on the last screen (VC5) I have a "home" button that the user can click to go back to the home screen (VC1), I've set it up so it pushes to VC1, the problem is when the user clicks that they are taken to the homescreen but then there is a back button on the navigation bar and they can go back to the last screen? After they click home they should not be able to return to previous screens without navigating through to them like they had the first time!
How can I accomplish this? Thanks! I'm used to working with xib and programmatically controlling the UINavigationControllers so this StoryBoard stuff is very new to me haha!
It sounds like you want an unwind segue. On the VC1 .m file add the following blank method:
- (IBAction)unwindToVC1:(UIStoryboardSegue*)sender
{
}
Then in your storyboard on VC5 Ctrl-drag from your home button to the green Exit button at the bottom of your view controller. Choose the unwindToMainMenu option and it should now go back to the VC1 when pressed and no longer have the back button as it has popped all the view controllers.
I think the method you're looking for is popToRootViewControllerAnimated:
[self.navigationController popToRootViewControllerAnimated:YES];

Non-Animated Storyboard Segues

I have an app in which there is a ViewController and once a button is pressed it goes to DetailViewController. In ViewController I have hidden the navigation bar to have more room to display an image while in DetailViewController it is necessary.
When I hit the back button in DetailViewController it goes back, however since it has a navigation bar and ViewController doesn't the animated segue looks bad. I was wondering, is there a way to make the default back button (that comes when embedded into navigation controller) give you a non animated segue?
Thanks
try using [[self navigationController] setNavigationBarHidden:{YES,NO} animated:{YES,NO}]; in view{Will,Did}{Dis}appear instead of setting everything up via Xcode UI controls
You can get good results WITH animation using them too.
If you really want to remove the whole animation, though: Prevent the animation when clicking "Back" button in a navigation bar?

Can't display UITabBarController after pushViewController

This is the flow I have:
Public screen with login button
Click login button will display a Modal screen
After successfully logged in, I push a UIViewController to the main screen which is in my storyboard designed as Tab Bar Controller with 3 different views
It did push to the intended view, but the UITabBar at the bottom is gone. So the view which should be inside UITabBarController is missing the bottom bar, I cannot navigate.
How can I solve this issue? or should I do something else instead of pushViewController:?
Thanks.

Resources