I'm having a strange graphical issue in iOS 7 on both, Simulator and Device.
I call a segue from the storyboard programmatically after a cell in a table view has been pressed:
[self performSegueWithIdentifier:#"showTerminDetailView" sender:self];
Then I inflate some values:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:#"showTerminDetailView"]) {
Termin *termin = [self termineAtDate:self.currentday][[((TerminDayTableViewTableViewController *)self.terminTableViews[3]).tableView indexPathForSelectedRow].row];
TerminDetailViewController *terminDetailViewController = segue.destinationViewController;
terminDetailViewController.termin = termin;
}
}
The problem is that the right side of the navigation bar becomes darker during the animation:
Any help is welcome!
This is normal behavior. iOS7 navigation bar is translucent by default so you can see what is beneath it. Your issue could be one of the following
The controller is set to only show beneath the navigation controller.
You have self.navigationController.navigationBar.translucent = NO; on your pushed view controller so it is changing from translucent to non translucent
You have self.edgesForExtendedLayout = UIRectEdgeNone; which is again moving the content down below which will make the nav controller not have content under it
You have something showing in your pushed view controller behind the nav bar.
Related
Here is my setup:
App launches with a main screen that has 4 buttons. each button takes you to a new view/childview. Each child view has a back button( via navigation controller) to take you back to the main/menu screen. Easy enough. And works great. however, here is what i want to do:
Main screen has 4 buttons to 4 different views. On the main screen all you see is the main page/menu, NO TABBAR. However, when you go to any of the 4 view options a tab bar will be present that is populated with tabs to the 4 child views. AND there will also be a navigation bar if we wanted to go back to the Main menu.
So essentially: Main Menu shows NO TAB BAR. 4 child views show Tab Bar AND navigation bar. I messed around with a bunch of stuff but can't get it to work. Any thoughts about how to do this?
You can achieve this by having your storyboard look like this:
Then in YourMainMenuViewController's implementation:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
UITabBarController *tabVC = segue.destinationViewController;
if ([segue.identifier isEqualToString:#"Tab1"]) {
tabVC.selectedIndex = 0;
}
else if ([segue.identifier isEqualToString:#"Tab2"]) {
tabVC.selectedIndex = 1;
}
else if ([segue.identifier isEqualToString:#"Tab3"]) {
tabVC.selectedIndex = 2;
}
else if ([segue.identifier isEqualToString:#"Tab4"]) {
tabVC.selectedIndex = 3;
}
}
Although I advise against putting a tab bar controller inside a navigation controller like this as it's kind of confusing UI.
To show navigationBar on viewWillAppear implement this
[self.navigationController setNavigationBarHidden:NO];
To show tabBar on viewWillAppear implement this
self.tabBarController.tabBar.hidden = NO;
You can set them YES to make them hidden in your menu on viewWillAppear
Hope it helps
I have views with a navigation bar and a tab bar. What I would like to happen is to hide the tab bar on a certain view and show the tab bar again when the user changes views.
I saw a snippet of code for hiding the tab bar:
-(void)makeTabBarHidden:(BOOL)hide
{
// Custom code to hide TabBar
if ( [tabBarController.view.subviews count] < 2 ) {
return;
}
UIView *contentView;
if ( [[tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] ) {
contentView = [tabBarController.view.subviews objectAtIndex:1];
} else {
contentView = [tabBarController.view.subviews objectAtIndex:0];
}
if (hide) {
contentView.frame = tabBarController.view.bounds;
}
else {
contentView.frame = CGRectMake(tabBarController.view.bounds.origin.x,
tabBarController.view.bounds.origin.y,
tabBarController.view.bounds.size.width,
tabBarController.view.bounds.size.height - tabBarController.tabBar.frame.size.height);
}
tabBarController.tabBar.hidden = hide;
}
from: http://nickwaynik.com/iphone/hide-tabbar-in-an-ios-app/
I call this on the view wherein I want the tab bar hidden
[self makeTabBarHidden:YES];
it works fine when i show/hide it on that view but when I navigate back to the previous view, the tab bar there is also hidden. I tried calling that function in the view's viewDidUnload, viewWillDisappear, viewDidDisappear functions but nothing happens. The same is true when the function is called in the previous view's viewDidLoad, viewWillAppear, viewDidAppear functions.
You can set the UIViewController.hidesBottomBarWhenPushed instead:
DetailViewController *detailViewController = [[DetailViewController alloc] init];
detailViewController.hidesBottomBarWhenPushed = YES;
[[self navigationController] pushViewController:detailViewController animated:YES];
[detailViewController release];
You can also do this in the Interface Builder for a storyboard. Select the View Controller that you want to hide the Tab Bar for and then select "Hide Bottom Bar on Push".
I just created a category on UITabBarController that allows you to hide the TabBar, optionally with an animation:
https://github.com/idevsoftware/Cocoa-Touch-Additions/tree/master/UITabBarController_setHidden
It adds the tabBarHidden property (with isTabBarHidden as its getter) and the - (void)setTabBarHidden:(BOOL)hidden animated:(BOOL)animated method.
Swift 3:
Set tab bar to hide in viewWillAppear or viewDidAppear
self.tabBarController?.tabBar.isHidden = true
Try this for hide / show:
- (void)viewWillDisappear:(BOOL)animated {
self.hidesBottomBarWhenPushed = NO;
}
- (void)viewWillAppear:(BOOL)animated {
self.hidesBottomBarWhenPushed = YES;
}
self.navigationController.hidesBottomBarWhenPushed=YES;
Add this line to your viewDidLoad or viewWillAppear; this will hide you tab from bottom.
The same property is available on the attributes inspector when you click on your view controller on your Xib or storyboard file.
you can use below code but tabBar remains hidden when you navigate back.
//hide tabbar
//self.tabBarController?.tabBar.isHidden = true
better way is to do through main.storyboard
check "Hide Bottom Bar on Push" as I've done.
I have an iOS app where there is a navigation controller as the root controller but at one part there is a tab bar to select between views in one of the nav bars. It looks similar to the iTunes app (navigation bar on top, tab bar on the bottom). I want the title of my navigation bar to change based on which tab is selected. I have two separate controller files for each tab. Here is what I have tried to use in each so far to fix this to no avail:
self.navigationItem.title = #"Title";
self.navigationController.navigationItem.title = #"title";
[self.navigationController setTitle:#"Live"];
[self setTitle:#"Top Title"];
How do I change the NavBar title based on which tab is pressed?
You change the title of the bar in the view controller that is currently being displayed.
So for example, in view controller A that you're showing in the tab controller, you might add:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
[self setTitle:#"A"];
self.tabBarController.navigationItem.title = #"A";
}
Same goes for B, C, etc.
In your ViewControllers that are in the tabs:
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.tabBarController.title = self.title;
}
If the individual view controllers presented by the tab bar controller have their own navigation bars, then
[self setTitle:#"Foo"];
will set both the tab bar label, as well as the navigation bar title.
If the navigation controller is at the top level (i.e. the tab bar is inside the navigation controller), then you might have to set the navigation bar title's manually (and you'll want to do this in viewDidAppear rather than viewDidLoad, because these child controllers are not reloaded every time you switch), e.g.:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.navigationController.navigationBar.topItem setTitle:#"Foo"];
}
Alternatively, you could do this navigation bar title adjustment in your UITabBarControllerDelegate method didSelectViewController.
If this doesn't do it, you might have to clarify your question, describing the hierarchy of controllers (e.g. is the tab bar controller inside navigation bar, or vice versa).
You can subclass the UITabBarController, set the delegate to itself, and use the delegate to set its title when the view controller is selected:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
//change the title based on viewController that is selected
self.title = #"New title";
}
Just Two Lines of Code..Only thing is, you need to use viewWillAppear method
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.tabBarController.navigationItem.title = #"Your Title";
}
PS: Inspired from Above Answers...
UITabBarController *tabController = (UITabBarController *)self.parentViewController;
tabController.navigationItem.title = #"ABC";
This is working for me
From some R&D on internet
You have to pass the navigationItem up the chain.
The UINavigationController shows the navigationItem belonging to its topViewController which is UITabBarController.
The UITabBarController shows the navigationItem titles in its tabs. So what you need to do is make sure that the tabBarController's navigationItem is it's selectedViewController's navigationItem
So to recap:
UINavigationController title = topViewController.navigationItem.title
UITabBarController tabTitle =
selectedViewController.navigationItem.title
UIViewController title = navigationItem.title
When pushing a view controller my toolbar buttons fade out and then in again with the new view. The problem is that i have the same buttons in the next view as the previous so it looks like the buttons do a quick flash when switching screen. My question is if this can be avoided by disable the fade out of toolbar buttons for the navigation controller when pushing to a new view or if the toolbar can be bound to the navigation controller in such a way that it is the same for all views. The last suggestion since i have seen that my navigation bar buttons does not fade out when pushing a new screen.
I'm surprised that nobody answered you. I've just faced this issue, and here's a solution I've found.
Subclass your navigation controller
Override you push/pop methods
-(UIViewController*)popViewControllerAnimated:(BOOL)animated
{
self.navigationBarHidden = YES;
UIViewController *vc = [super popViewControllerAnimated:animated];
self.navigationBarHidden = NO;
return vc;
}
-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
self.navigationBarHidden = YES;
[self pushViewController:viewController animated:animated];
self.navigationBarHidden = NO;
}
It did the trick for me.
I know this question is old, but there is a simple solution: Set both controller's navigation items to the same bar button item, and it won't animate. Eg:
UIBarButtonItem* item = [[UIBarButtonItem alloc] initWith...];
viewController1.rightBarButtonItem = item;
viewController2.rightBarButtonItem = item;
If you now push viewController2 after showing viewController1, the navigation item will not animate.
For building up a toolbar in the code, I think it should be in the ViewWillAppear lifecycle method. I had previously built up a toolbar in code but in ViewDidLoad, and I saw this quick fade in/fade out
I have views with a navigation bar and a tab bar. What I would like to happen is to hide the tab bar on a certain view and show the tab bar again when the user changes views.
I saw a snippet of code for hiding the tab bar:
-(void)makeTabBarHidden:(BOOL)hide
{
// Custom code to hide TabBar
if ( [tabBarController.view.subviews count] < 2 ) {
return;
}
UIView *contentView;
if ( [[tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] ) {
contentView = [tabBarController.view.subviews objectAtIndex:1];
} else {
contentView = [tabBarController.view.subviews objectAtIndex:0];
}
if (hide) {
contentView.frame = tabBarController.view.bounds;
}
else {
contentView.frame = CGRectMake(tabBarController.view.bounds.origin.x,
tabBarController.view.bounds.origin.y,
tabBarController.view.bounds.size.width,
tabBarController.view.bounds.size.height - tabBarController.tabBar.frame.size.height);
}
tabBarController.tabBar.hidden = hide;
}
from: http://nickwaynik.com/iphone/hide-tabbar-in-an-ios-app/
I call this on the view wherein I want the tab bar hidden
[self makeTabBarHidden:YES];
it works fine when i show/hide it on that view but when I navigate back to the previous view, the tab bar there is also hidden. I tried calling that function in the view's viewDidUnload, viewWillDisappear, viewDidDisappear functions but nothing happens. The same is true when the function is called in the previous view's viewDidLoad, viewWillAppear, viewDidAppear functions.
You can set the UIViewController.hidesBottomBarWhenPushed instead:
DetailViewController *detailViewController = [[DetailViewController alloc] init];
detailViewController.hidesBottomBarWhenPushed = YES;
[[self navigationController] pushViewController:detailViewController animated:YES];
[detailViewController release];
You can also do this in the Interface Builder for a storyboard. Select the View Controller that you want to hide the Tab Bar for and then select "Hide Bottom Bar on Push".
I just created a category on UITabBarController that allows you to hide the TabBar, optionally with an animation:
https://github.com/idevsoftware/Cocoa-Touch-Additions/tree/master/UITabBarController_setHidden
It adds the tabBarHidden property (with isTabBarHidden as its getter) and the - (void)setTabBarHidden:(BOOL)hidden animated:(BOOL)animated method.
Swift 3:
Set tab bar to hide in viewWillAppear or viewDidAppear
self.tabBarController?.tabBar.isHidden = true
Try this for hide / show:
- (void)viewWillDisappear:(BOOL)animated {
self.hidesBottomBarWhenPushed = NO;
}
- (void)viewWillAppear:(BOOL)animated {
self.hidesBottomBarWhenPushed = YES;
}
self.navigationController.hidesBottomBarWhenPushed=YES;
Add this line to your viewDidLoad or viewWillAppear; this will hide you tab from bottom.
The same property is available on the attributes inspector when you click on your view controller on your Xib or storyboard file.
you can use below code but tabBar remains hidden when you navigate back.
//hide tabbar
//self.tabBarController?.tabBar.isHidden = true
better way is to do through main.storyboard
check "Hide Bottom Bar on Push" as I've done.