How to reset the Navigation Controller in Xcode 6? - ios

Im working on an App for iOS, thats uses the navigationController to switch betweens views. I'm trying to return from to the root viewcontroller from the third view.
I have succeeded in the Main.Storyboard, with dragging a button from third to root view, but then the NavigationController just continues the stack.
Is it possible to make a command from third view, to return to root ViewController, without the NavigationController Bar showing the "Back" button and keeping track and without reseting any Bools.

If you want to hide the back button from the navigation bar.Then write the code in third view's viewDidLoad or in viewWillAppear-
self.navigationItem.hidesBackButton=YES;
And Now write the code in the body of the action button.Such as-
[self.navigationController popToRootViewControllerAnimated:YES];
Let me know if it works for you.Thank you

You can use the [UINavigationCobtroller popToRootViewControllerAnimated:] to close all the view hierarchy to the first but for the remaining issues you can find plenty of answers on SO.

Related

Swift iOS app - issue with change storyboard segue kind - cant change from modally to show

As you can see - i selected show but on main storyboard and in app it works like modaly.
What's wrong with it?
Even if i change to any other option, it works modally!
Edit: If i add button and segue to other view - it works always modally to even if i change this value.
For appearing with "Back" button in the navigation bar, you need to use Navigation Controller at first. In order to can push inside.
Check the image, Now it will be handled to push inside the stack of the view controllers of the navigation controller.

Swift NavigationControllerBar Back Button

I am new in iOS development and in Swift. I have a question. I added in one of the ViewController NavigationController. But I have some problems with back button cause it doesn't appear on other Views. I tried with self.pushViewController() and with self.present() but it doesn't work. If I mark in NavigationController Is Initial View Controller then everything is fine but I don't want it because then app starts with this screen(where I have NavigationController).
Please help me, what I should to add or to write?
This is an image of my storyboard
And this is what I have if I run and go to another ViewController, as you can see I don't have navigation bar and back button.
You got 2 options :
1) Add a navigation controller in the root ViewController, Hide throughout except the last one. Make sure you push the last VC so Back option will be there by default
self.navigationController.pushToViewController(BarCodeViewController)
2) Use a custom View on top of last viewController add a custom button to that view. But this time present it from previous ViewController
self.present(BarCodeViewController)
when back button clicked dismiss it by adding target to the button. self.dismiss()

Unable to configure UINavigationBar for view embedded in Tab Bar Controller

I a writing an app (iOS8) that ultimately needs to load a UITabBarController via a segue from a UITableView. For the most part this setup can be done via Storyboards and works as expected, however I would also like to add a UIButtonBarItem to the destination view which is where the problems start.
A setup that works (without a UITabBarController) can be configured as follows
The button uses a "Show" segue to display the final view controller
The second UIBarButtonItems are added by copying over the Navigation Item from the first view controller (How to add buttons to navigation controller visible after segueing?)
If I run this in the Simulator, everything works as expected and I see both the back button and the desired "Add" UIBarButtonItem:
If I then embed the final view controller in a UITabBarController, the UIBarButtonItem I added disappears and so far any changes I have made to the storyboard setup (adding a UINavigationController in between the UITabBarContoller and the last view for example) or attempts to add the UIBarButtonItem programatically don't make a difference:
Is there anyway to get the final setup working with both a UITabBarController and UIBarButtonItems?
I have the same setup in one of my apps and it works fine. Not sure why you are having issues, but I did add a few lines of code in my custom Tab Controller that may help you. I think the issue is that the nav bar from the original navigation controller is still being shown, so subclass UITabBarController and put these lines in viewWillAppear:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationItem setHidesBackButton:YES];
[self.navigationController setNavigationBarHidden:YES];
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
In my app, the views before the tab bar controller were login/register views, so there was no reason to navigate back to them after entering the tab controller "stack," but I'm sure it won't be difficult to add a back button that accomplishes this. I believe you only need the [self.navigationController setNavigationBarHidden:YES]; line, which only hides the nav bar instead of hiding the back button or disallowing the pop gesture.
I know this is late but I just want to add swift 3 code.
The reason being that the NavigationBarA of the tabBarController is hiding your NavigationBarB that sits in between your tabBarController and the final ViewController. So you just have to set to hide the NavigationBarA
in viewWillAppear of your final ViewController you can add the following (without a need to subclass tabBarController)
self.tabBarController?.navigationController?.setNavigationBarHidden(true, animated: false)

Bypass UIView without showing

I am using Storyboards for an iOS 7 App. The root controller is a menu. For almost every view, I have a Menu button which brings the App back to that menu using [self.navigationController popToRootController:TRUE]. However, there are two UIView elements where I would like to clear the Navigation Controller view list (as happens when you pop back to the root controller), but then immediately go to another UIView without having the user see the root controller's view. Once at this new view, if the user presses the back button, I want them to go to the menu view.
I've tried to put a performSegue in the viewWillAppear, but it really messes up the Navigation Controller and views. I've tried putting a performSegue in the viewDidAppear, but the user sees first the Menu view flash in, then out on it's way to the correct view.
I hope I've explained this well enough. I hope this can be done.
Thanks.
Your best bet is to build the navigation controller stack yourself, and then use - (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated: to replace the current stack.
So you could do something like
...
UIViewController *vcToPush = ...;
NSArray *newVCStack = #[[self.navigationController.viewControllers firstObject], vcToPush];
[self.navigationController setViewControllers:newVCStack animated:YES];
This will add your new controller to the stack using the standard push animation (or not if you so choose), and after the animation is complete, set the view stack to that of the array.

how to add Back button to go back to previous MonoTouch storyboard view?

In my Xamarin Studio C# MonoTouch storyboard, I have several views and each one has a button to do a modal seque to common view call "ultrasound".
How do I add a Back button to Ultrasound view that will go back to previous view?
I sequed each view by modal to the Ultrasound view.
I added the Ultrasound Back button wired to method button_ultrasound_back, but nothing happens:
Ultrasound_Controller.m
- (IBAction)button_ultrasound_back:(id)sender {
[self.navigationController popViewControllerAnimated:YES];
}
When I try moving the popViewControllerAnimated line into Ultrasound_Controller.cs, then the "self" causes an error.
And, if I change the seques from other view to Ultrasound view from modal to push, then Ultrasound view crashes app.
You need to use the push segue as apposed to a modal. Push requires you to have a UINavigationController and you first view set as its initial view controller. Once you have done this back buttons happen for free, no need to code them yourself.
This is a good intro into Storyboards. It is Obj-C but easy to follow.

Resources