Iphone: Unhiding a Tab bar and Navigation Bar after Navigation - iphone

I have a UItabbarController and inside the first tab a UINavigationController. In interface builder I have set the tab bar and navigation bar as hidden.
When the first screen loads up (which is a UIVewcontroller in the Uinaviagtioncontroller of the first tab) I set an NStimer for 2 seconds. After which it navigates to a second view. Now when this happens I want the navigation bar and tabbar to appear, and it should be animated.
This what I am doing right now.
First UIViewController:
- (void)viewDidLoad {
[super viewDidLoad];
splashTime = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:#selector (action) userInfo:nil repeats:NO];
}
-(void)action{
SecondViewController *m = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
[self.navigationController pushViewController:m animated:YES];
}
Second UIViewController:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
self.hidesBottomBarWhenPushed = NO;
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
return self;
}
But nothing is really happening. Neither the Tabbar or the NavigationBar appears.

Try place the code for your Second View Contoller inside the viewWillAppear method instead of the initWithNibName method and see if that has the desired outcome:
- (void) viewWillAppear:(BOOL)animated {
self.hidesBottomBarWhenPushed = NO;
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
That way it should be called everytime the view is about to display.

Related

iOS Navigation bar smooth transition

I have an app where the first screen (the menu for the app) does not need a navigation bar BUT the rest of the app does.
The code I am using works fine in the sense that the navigation bar is not present on the menu screen and is present elsewhere in the app BUT the BIG PROBLEM is that once you go back to the menu the navigation bar appears for about a split second and then disappears.
That is NOT a very smooth transition.
How do I make the transition SMOOTHER so that the navigation bar DOESN'T even appear for a second when I go back to the menu screen?
Here is the code that I am using:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
[self.navigationController setNavigationBarHidden:YES animated:NO];
}
return self;
}
- (void)viewDidLoad {
[self.navigationController setNavigationBarHidden:YES animated:NO];
[super viewDidLoad];
}
-(void) viewDidAppear: (BOOL)animated {
[[self navigationController] setNavigationBarHidden:YES animated:NO];
[super viewDidAppear:animated];
}
Try like this,
-(void) viewWillAppear: (BOOL)animated {
[super viewWillAppear:animated];
[[self navigationController] setNavigationBarHidden:YES animated:YES];
}
Hope it may helps you...
In your first view controller:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
In your second view controller (not needed, but good practice for code clarity) :
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
set this in the view did disappear in first screen of the app
[[self navigationController] setNavigationBarHidden:NO animated:YES];
and this in viewdiddisappear of the second VC
[self.navigationController setNavigationBarHidden:YES animated:NO];
Instead of hiding and showing the navigation bar, you can update the alpha for the navigation bar. It will animate smoothly during the transition. For the view controller with transparent nav bar, instead of modifying the nav bar, create a navbar (or just the back button and title etc.) manually in the second controller's view. We will then hide the navbar when transitioning from first view controller to the second one.
On your second controller's viewWillDisappear and on your first view controller's viewWillAppear:, set the navigation bar alpha to zero using self.navigationController.navigationBar.alpha = 0;. Since this is in animation block, this will make the navigation bar disappear during the push animation.
Set the alpha back to one in second controller's viewWillAppear and first controller viewWillDisappear.

UITableViewController doesn't have navigation bar when pushed

I'm using this code
-(void)gotoInformationViewController:(id)sender
{
MoreViewController *moreViewController = [[MoreViewController alloc] init];
[self.navigationController pushViewController:moreViewController animated:YES];
[moreViewController release];
}
to push a MoreViewController (which is UITableViewController) but it doesn't have UINavigationBar when pushed, just UITableView on whole screen.
Try this in your view Controllers
- (void) viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillAppear:animated];
}
and make sure in interface builder your viewcontroller's top bar is not set to none

Hide backbar button in navigationbar in iPhone sdk

In my iPhone App there are three views, firstView, secondView and thirdView.
now I want to put Back Button in navigation bar in thirdView only which should take me to back secondView only
for that i m writing this code in first view
self.navigationItem.hidesBackButton:NO;
and it shows the back button in both the views secondView and thirdView
what I should do to hide back button in the the secondView?
I think you have to set [self.navigationItem setHidesBackButton:YES] in your secondView.
And set [self.navigationItem setHidesBackButton:NO] in your thirdView.
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationItem.backBarButtonItem=nil;
}
OR
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationItem.hidesBackButton=YES;
}
To hide the back button in the navigation bar
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
self.navigationController.navigationBar.topItem.hidesBackButton = YES;
}
To show the back button in the navigation bar
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
self.navigationController.navigationBar.topItem.hidesBackButton = NO;
}

backButton of NavigationController don't appear

I have already post this question but this time I post code. So I have a uiviewController, and in the viewDidLoad of this viewController I hide the backButton of the navigationController. After that, I push a new uiviewcontroller, and I set the backbutton to visible in the viewDidLoad, but the backbutton is still hidden...
Implementation of the first uiviewcontroller
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = #"page2page2page2page2page2";
self.navigationItem.hidesBackButton = TRUE;
}
-(IBAction)click
{
page3 *controller = [[page3 alloc] init];
[self.navigationController pushViewController:controller animated:YES];
[page3 release];
}
Implementation of the page 3
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = #"page3";
self.navigationItem.hidesBackButton = FALSE;
}
and the page3 has no backbutton, but the space is created for the button, because the tile "page 3" is on the right and not in the center... all this happen with the ios 4.2
thx
Neither of the above workarounds seemed to work for me. However when the third view was being displayed, i could see the button blink for a moment. So I suspected the problem (bug) has to do with the animation
When change animated to NO on the pushViewController the problem went away
- (IBAction)btnNext:(id)sender {
[[self navigationController] pushViewController:thirdViewController animated:NO];
}
My trick is setting setNavigationBarHidden to YES and immediately NO.
[self.navigationItem setHidesBackButton:NO animated:YES];
[self.navigationController setNavigationBarHidden:YES];
[self.navigationController setNavigationBarHidden:NO];
So as this the backButton not be animated but it's really work and my manager have not notice it ;P
I get the same behaviour and I must say I find it quite strange. I can't say why it doesn't work but as a workaround you can do:
In page2:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.navigationItem setHidesBackButton:YES animated:YES];
}
And in page3:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.navigationItem setHidesBackButton:NO animated:YES];
}
And remove the calls to self.navigationItem.hidesBackButton = ... in both controllers.
Well, I had the same problem running iOS 4.2. The back button would refuse to appear. Upon autoroating to landscape, it then appears. My solution was to do the following - This fixed the problem...or should we say its a workaround ;)
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.hidesBackButton = YES;
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
self.navigationItem.hidesBackButton = NO;
}

"Hide" the Tab Bar When Pushing a View

The New York Times iPhone application has a Tab Bar with five tab bar items. When you select the Latest tab, the app shows the title and abstract/summary in a UITableView. When you select an individual story to read, the Tab Bar disappears and is replaced with a header and footer that appears/disappears depending on the state of the app. How does the app "hide" the tab bar?
Thanks!
Implement this piece of code in the class where you want to hide the Tab Bar.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
// Custom initialization
}
self.hidesBottomBarWhenPushed = YES;
return self;
}
All the best.
The view controller that is being pushed onto the navigation controller stack has its hidesBottomBarWhenPushed parameter set to yes. The code would look something like this in the table view's -didSelectRowAtIndexPath.
NSDictionary *newsItem = [newsItems objectAtIndex:[indexPath row]];
NewsDetailViewController *controller = [[NewsDetailViewController alloc] init];
[controller setHidesBottomBarWhenPushed:YES];
[controller setNewsItem:newsItem];
[[self navigationController] pushViewController:controller animated:YES];
[controller release], controller = nil;
Take a look at the documentation for hidesBottomBarWhenPushed.
p.s. You'll probably get more visibility on this question if you add the tag 'iphone' to it.
I have a view that needs to optionally (depending on some other state) show the navigation controller toolbar. This is the solution I used to show & hide the toolbar (with animation) when the view appears & disappears via navigation. It sounds like what you might be after.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
// Show the nav controller toolbar if needed
if (someBool)
[self.navigationController setToolbarHidden:NO animated:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
// Hide the nav controller toolbar (if visible)
[self.navigationController setToolbarHidden:YES animated:animated];
}