Unable to configure UINavigationBar for view embedded in Tab Bar Controller - ios

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)

Related

How to reset the Navigation Controller in Xcode 6?

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.

Remove navigation bar from main controller in Xcode?

I have a main view controller in Xcode 6 (program is in swift) on which I have a few buttons that lead to certain navigation controllers. When I test the app, the first time I see it it looks fine (without a navigation bar at the top). When I click on a button on main view controller, it shows the navigation controller I selected, everything acts perfectly again. The problem happens when I click on the bar button "back" on that nav controller in order for it to show me my main view controller again. When I'm back to the main view controller, there's a navigation bar at the top that isn't supposed to be there. I want my main view controller to have no navigation bar at the top. I tried to use push, modal and show segues to see if it might be the problem, but I still can't figure it out. Any thoughts on what might be happening?
Sounds like you need to re-hide your navigation bar. To do that, add:
self.navigationController?.navigationBarHidden = true
to the viewWillAppear of whatever view controller for which you'd like to hide the nav bar.
Updated for Swift 3:
self.navigationController?.isNavigationBarHidden = true
In mainViewController, write code to hide navigation bar in viewWillAppear method.
in Objective-C
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[[self navigationController] setNavigationBarHidden:YES animated:NO];
}

UIBarButton unclickable in empty ViewControllers

i've created a tabBarController subclass and linked 3 viewcontrollers to the TabBarController in the storyboard. In the 3 ViewControllers which is directly connected with the tabBarController the UIBarButtons wont react when i click. They wont show the log message and does not do the highlight color. It seems like the navigationBar interaction is disabled or something. When i present a view modally on top of one of the 3 ViewControllers i have no problem with interaction with a UIBarButton in the modally presented View. I'm wondering what could result in such? i've struggled with this for ours.
i don't know if this has anything to do with it aswell, but in the modally presented views this does also result in white statusBar textColor, but it does not change it in the 3 views connected to the TabBarController.
What could this issue be?
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.navigationController.navigationBar.translucent = NO;
i've simply manually added a UIBarButton in the storyboard and then connected this action.
-(IBAction)testAction :(id)sender {
NSLog(#"test");
}
Try this
You just take 3 Navigation Controller as your tab bar view controller rather than simply view controller.
And connect tab bar view controller with navigation controller.
On navigation controller there is one view controller, on that navigation bar put your bar button item and connect to IBAction Method.
Its works for me.

Safe way to remove tab bar from UITabBarController in ios

I want to use UITabBarController but I do not need a tab bar because I'm going to switch tabs from the menu in another view controller. I want to remove it as it will be never used. I've created a subclass of UITabBarController and put this code:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.tabBar removeFromSuperview];
}
Is that safe to remove tab bar that way?
Update: Why tab bar controller?
Apple suggests to use standard container view controllers whenever it possible. I'm trying to follow that. My screens workflow is the same as for tabs, except that they are switched by left side menu, not by the tab bar.
When I use a UIViewController and change it's child view controller I've got a lot of problems when autolayouts are not working properly.
The other reason is that I want to use story board, rather then create segues from the code so I can see my app workflow easily.
When you are saying, you don't want to use it, then why to remove it. You can go with a
tabbarcontroller with hidden tabbar. I am switching tabs from the bottom custom bar.
I am doing an app, which has a tababr controller with three items. Instead of using system tab, I am creating a custom view at the footer like tab & have actually set the hidden property of tabbarController's tabbar to YES.
myTabBarController.tabBar.hidden = YES;
Try this code
[app.navigationController.view removeFromSuperview];
[app.tabbarcontroller.view removeFromSuperview];
[app.window addSubview:app.navigationController.view];
[app.navigationController popToRootViewControllerAnimated:YES];

NavController push from subview

I got an application with a tabbar and a navigation controller for one of the tab view.
The Navigation controller is pushing several views and one of them has a button which permits to add a subview (I am actually displaying a popup message -not an uialert- when pushing that button).
The problem is that I would like now to be able to push a new view controller once I pushed a button in the subview...
I cannot find my navcontroller, even when I use the pushmethod of appdelegate.tabbar.navigationController
Does one of you have easy idea about how to implement that ?
Thanks a lot !
If the button's press action of the second button is being handled in the same UIViewController as the other button's action you should simply be able to use
[self.navigationController pushViewController:newViewController animated:YES];.
If your subview has it's own UIViewController you could add a reference to your first UIViewController or to the navigationController itself and use it that way.

Resources