Navigation Controller and View Controller - ios

I need return to the principal view , when i press the button in the first view of the navigation controller....
I have connect one simple view and this view go to the navigation controller..
ViewController --> Navigation Controller --> View of Navigation
<----------------------------------------------
How i can do this....

You want to return to the top Root ViewController :
navigationController?.popTopRootViewControllerAnimated(true)
if you want to return into the previous viewController:
navigationController?.popViewControllerAnimated(true)

To answer this using IB:
CTRL + Drag your button to your VC and create a modal segue.

Related

how to start third view controller of navigation controllers on tab bar in storyboard

Tab bar have three view controllers. and I want to start third view controller of navigation controller when opening the tab bar. When tapping back button on third view controller, move to second view controller.
How to start third view controllers and push first, second view controllers.
It has each segue.
just access your navigation controler and call setViewControllers
let nvc = (tabBarController?.viewControllers?[0] as? UINavigationController)
nvc?.setViewControllers([UIViewController1, UIViewController2, UIViewController3], animated: false)

Multiple segues remove navigation bar in view controller

I have a view controller that has a navigation bar. It is the root view controller of the navigation controller. I have another view controller that can be segued from a button on the first controller. Up to this point, everything works fine; there are navigation bars on both view controllers.
However, from the second view controller, I want to be able to segue back to the first controller. When doing this, it removes the navigation bar from both of the view controllers.
How can I get the navigation bar on both view controllers with buttons as transitions? Thanks!
Implement below method in your both viewcontroller,
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
You may hiding navigationbar somewhere.
Try this in storyboard:
Select the navigation controller -> Attributes Inspector -> Under Navigation controller and Bar Visibility leave the "Show navigation bar" blank

Why TabBar hides after the segue?

I have the next structure:
* TabBarController
- ViewController with TableView
- ViewController
When I select any row on the TableView, the segue forwards me to the ViewController. On the ViewController with the TableView, I see the BottomBar, but after the segue it disappears.
How can I keep it on my ViewController? I've even putted the last ViewController in NavigationController, but it did not help me, too.
How can I fix it?
Your hierarchy should look like this:
* TabBarController
- NavigationController
- ViewController with TableView
- ViewController
Using a Show segue with an UINavigationController pushes the destination view controller onto the navigation stack. However, most other view controllers present the view modally (i.e. by sliding over the source view controller) with Show, which is why your tabbar disappears.
uncheck hide bottom bar when pushed from your view controller in story board

Different UIBarButtonItems if Pushed or Modal

I am trying to use different Navigation Bar Button Items for a single View Controller.
The View Controller can be :
pushed inside a Navigation Controller
presented modally inside a navigation controller
If it's presented modally, I need a close left bar button to dismiss the modal.
Is there a way to know if the VC is presented modally in order to set a dismiss left bar button accordingly?
I solved this problem by implementing such a method on UIViewController category
and then using this method in viewDidLoad to determine, whether the current controller presented modally or by pushing into navigation controller:
- (BOOL)isModal {
if (self.viewController.navigationController && self.viewController.navigationController.viewControllers.firstObject == self.viewController) {
return YES;
}
return NO;
}

Is there a way to pop back to previous navigation controller?

I have a base nav controller which has a tab bar controller nested inside. inside that tab bar controller is another nav controller nested in it. If I'm in the child nav controller I can pop to root view in one of the views but it only takes me to the root view of the CHILD nav controller. Is there a way to pop back to the first nav controller?
If you are using storyboard then you can use Unwind segue approach which always works for me
Just Control + drag from "Pop to Main Screen" UIButton to Exit (green button at bottom of scene) select unwind method declared in first screen with title "Main" e.g.
-(IBAction)customUnwind:(UIStoryboardSegue *)sender
{
NSLog(#"Unwind successful");
}
Try this,
You can pop to root view from the child nav controller by
UITabBarController *tc = (UITabBarController *)self.navigationController.parentViewController;
[tc.navigationController popToRootViewControllerAnimated:YES];

Resources