How to handle navigationController on other class - iphone

i have class like this
DrillDownAppAppDelegate.h
PictureCell.h
RootViewController.h
SlideShowViewController.h
DrillDownAppAppDelegate.m
PictureCell.m
RootViewController.m
SlideShowViewController.m
i want to hide my navigation bar,in class SlideShowViewController when i tap on the screen
but it doesn't work
my code is
[self.navigationController setNavigationBarHidden:YES animated:YES];

Assuming RootViewController is the visible view controller on the UINavigationController stack, simply push SlideShowViewController as normal, however in SlideShowViewController, include this code:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}

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

Presenting a Custom UIViewController without a NIB ? iPad

I have a view based application. I am trying to load a second custom view controller when the app starts. I have the following code :
- (void)viewDidLoad
{
controller = [NewController alloc];
[self presentModalViewController:controller animated:YES];
[controller release];
[super viewDidLoad];
}
The problem is that the new view controller is not loading and viewDidLoad is not called. I have no xib file for the second view controller.
Can anyone help ?
It won't work in your viewDidLoad or viewWillAppear methods. Use viewDidAppear instead.
You're missing a call to init your view controller...
- (void)viewDidLoad
{
controller = [[NewController alloc] init];
[self presentModalViewController:controller animated:YES];
[controller release];
[super viewDidLoad];
}

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;
}

Iphone: Unhiding a Tab bar and Navigation Bar after Navigation

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.