Showing posts with label UINavigationController example. Show all posts
Showing posts with label UINavigationController example. Show all posts

Sunday, June 9, 2013

UINavigationController UINavigationControllerHideShowBarDuration example in Objective C (iOS).


UINavigationController UINavigationControllerHideShowBarDuration

A global variable that specifies a preferred duration when animating the navigation bar.

extern const CGFloat UINavigationControllerHideShowBarDuration
Constants
UINavigationControllerHideShowBarDuration
This variable specifies the duration when animating the navigation bar. Note that this is a constant value, so it cannot be set.

UINavigationController UINavigationControllerHideShowBarDuration example.
[self.navigationController setNavigationBarHidden:YES animated:YES];
 [UIView transitionWithView:self.view
                   duration:UINavigationControllerHideShowBarDuration
                    options:UIViewAnimationOptionCurveLinear
                 animations:^
  {
   /* Put other animation code here ;) */
  }
                 completion:^(BOOL finished)
  {                                 
  }];

Example of [UINavigationController UINavigationControllerHideShowBarDuration].
- (void)pushViewControllerAfterAnimation:(UIViewController *)viewController animated:(BOOL)animated {
    [UIView transitionWithView:viewController.view
                      duration:UINavigationControllerHideShowBarDuration
                       options:UIViewAnimationCurveEaseOut
                    animations:^{
                        [self.navigationController setNavigationBarHidden:NO];    
                    }
                    completion:^(BOOL finished){
                        NSLog(@"animation finished");
                        [self pushViewController:viewController animated:animated];
                    }];
}

- (void)popViewControllerAfterAnimationAnimated:(BOOL)animated {
    [UIView transitionWithView:self.visibleViewController.view
                      duration:UINavigationControllerHideShowBarDuration
                       options:UIViewAnimationCurveEaseOut
                    animations:^{
                        [self.navigationController setNavigationBarHidden:YES];    
                    }
                    completion:^(BOOL finished){
                        NSLog(@"animation finished");
                        [self popViewControllerAnimated:animated];
                    }];
}

UINavigationController UINavigationControllerHideShowBarDuration example.
Only improvement would be setting anim duration to be consistent with other navigation controller animations:

    [UIView setAnimationDuration:UINavigationControllerHideShowBarDuration];

End of UINavigationController UINavigationControllerHideShowBarDuration example article.

UINavigationController setViewControllers example in Objective C (iOS).


UINavigationController setViewControllers

Replaces the view controllers currently managed by the navigation controller with the specified items.

- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated

Parameters of [UINavigationController setViewControllers]
viewControllers
The view controllers to place in the stack. The front-to-back order of the controllers in this array represents the new bottom-to-top order of the controllers in the navigation stack. Thus, the last item added to the array becomes the top item of the navigation stack.
animated
If YES, animate the pushing or popping of the top view controller. If NO, replace the view controllers without any animations.

Discussion of [UINavigationController setViewControllers]
You can use this method to update or replace the current view controller stack without pushing or popping each controller explicitly. In addition, this method lets you update the set of controllers without animating the changes, which might be appropriate at launch time when you want to return the navigation controller to a previous state.[UINavigationController setViewControllers]

If animations are enabled, this method decides which type of transition to perform based on whether the last item in the items array is already in the navigation stack. If the view controller is currently in the stack, but is not the topmost item, this method uses a pop transition; if it is the topmost item, no transition is performed. If the view controller is not on the stack, this method uses a push transition. Only one transition is performed, but when that transition finishes, the entire contents of the stack are replaced with the new view controllers. For example, if controllers A, B, and C are on the stack and you set controllers D, A, and B, this method uses a pop transition and the resulting stack contains the controllers D, A, and B.

UINavigationController setViewControllers example.
Finally I found the solution. The mistake was that the new top-level NavigationController has not been initialized and loaded properly until the animation is done. In my case, UserAssignmentsListViewController has a viewDidLoad method that will not be called until animation is done, but it sets the navigation title (here: a UIButton). Therefore the animation fails.

The solution is to refer to an already initialized view controller when it comes to pushing it to the stack. So initialize our top-level VC somewhere:

// initialize our top-level controller
ViewController* viewController2 = [[[ViewController alloc]
    initWithNibName:@"ViewController" bundle:nil] autorelease];
Then when pushing two or more VCs to the stack, the top level one is already initialized and the animation works (following the example from my original question):

NSMutableArray* viewControllers = [NSMutableArray arrayWithCapacity:2];
// put us on the stack, too
[viewControllers addObject:self];

ViewController* viewController1 = [[[ViewController alloc]
    initWithNibName:@"ViewController" bundle:nil] autorelease];
[viewControllers addObject:viewController1];

if (someCondition == YES)
{
    [viewControllers addObject:viewController2];
}

[self.navigationController
    setViewControllers:[NSArray arrayWithArray:viewControllers] animated:YES];

Example of [UINavigationController setViewControllers].
//Create view controller which confirms backup/restore complete
ConfirmationViewController *v = [[ConfirmationViewController alloc] init];

//Create array containing only root view controller and confirmation view controller
NSArray *viewControllers = [[NSArray alloc] initWithObjects:[self.navigationController.viewControllers objectAtIndex:0], v, nil];
[v release];

//Push the confirmation view controller so the user can see it
[self.navigationController pushViewController:v animated:YES];

//Set navigationController's viewControllers array in order to remove the intermediary view controllers. Back button now goes back to root viewController
[self.navigationController setViewControllers:viewControllers animated:YES];
[viewControllers release];

UINavigationController setViewControllers example.
[self performSelector: @selector(launchPhotoViewer)
                                   withObject: nil
                                   afterDelay: 0.1];

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

PhotoTest1Controller* test = [[PhotoTest1Controller alloc] init];
        [navigationController pushViewController:test animated:NO];

        // Remove previous view the hard way
        NSArray* orig = [navigationController viewControllers];
        NSMutableArray* newa = [[NSMutableArray alloc] init];
        for (id i in orig)
        {
                [newa addObject:i];
        }
        [newa removeObjectAtIndex:[orig count]-2];
        [navigationController setViewControllers:(NSArray*)newa]; 

End of UINavigationController setViewControllers example article.

UINavigationController pushViewController example in Objective C (iOS).


UINavigationController pushViewController

Pushes a view controller onto the receiver’s stack and updates the display.

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated

Parameters of [UINavigationController pushViewController]
viewController
The view controller that is pushed onto the stack. This object cannot be an instance of tab bar controller and it must not already be on the navigation stack.
animated
Specify YES to animate the transition or NO if you do not want the transition to be animated. You might specify NO if you are setting up the navigation controller at launch time.

Discussion of [UINavigationController pushViewController]
The object in the viewController parameter becomes the top view controller on the navigation stack. Pushing a view controller results in the display of the view it manages. How that view is displayed is determined by the animated parameter. If the animated parameter is YES, the view is animated into position; otherwise, the view is simply displayed in place. The view is automatically resized to fit between the navigation bar and toolbar (if present) before it is displayed.[UINavigationController pushViewController]

In addition to displaying the view associated with the new view controller at the top of the stack, this method also updates the navigation bar and tool bar accordingly. In iOS 3.0 and later, the contents of the built-in navigation toolbar are updated to reflect the toolbar items of the new view controller. For information on how the navigation bar is updated, see “Updating the Navigation Bar.”

Important: In iOS 2.2 and later, if the object in the viewController parameter is already on the navigation stack, this method throws an exception. In earlier versions of iOS, the method simply does nothing.
UINavigationController pushViewController example.
- (void) viewDidAppear
{   
    [self performSelector:@selector(loginCheck:) withObject:nil afterDelay:0.5];
}   
- (void) loginCheck:(id)sender
{
    LoginViewController * lvc = [[LoginViewController alloc] init];
    //lvc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [lvc setDelegate:self];
    //[self presentModalViewController:lvc animated:YES];  
    [self.navigationController pushViewController:lvc animated:YES];  
}

Example of [UINavigationController pushViewController].
- (void)viewDidLoad {
[super viewDidLoad];
    UINavigationController *navigationController
navigationController = [[UINavigationController alloc] init];
[self.view addSubview:navigationController.view];  

switch (whichViewController) {
    case 1:
        viewController = [[xxxx alloc] init];          
        break;
    case 2:
        viewController = [[xxx1 alloc] init];          
        break;
    default:
        break;
}

[navigationController pushViewController:viewController animated:NO];
[viewController release];
}

UINavigationController pushViewController example.
- (void)ShowPageWithIMDevicePage:(id<IMDevicePage>)page {
    YourDelegate* delegate = (YourDelegate*)[[UIApplication sharedApplication] delegate];
    IPhonePage* pageVC = (IPhonePage*)page;
    [delegate.navigationController pushViewController:pageVC animated:YES];
}

End of UINavigationController pushViewController example article.

UINavigationController popViewControllerAnimated example in Objective C (iOS).


UINavigationController popViewControllerAnimated

Pops the top view controller from the navigation stack and updates the display.

- (UIViewController *)popViewControllerAnimated:(BOOL)animated

Parameters
animated
Set this value to YES to animate the transition. Pass NO if you are setting up a navigation controller before its view is displayed.

Return Value of [UINavigationController popViewControllerAnimated]
The view controller that was popped from the stack.

Discussion of [UINavigationController popViewControllerAnimated]
This method removes the top view controller from the stack and makes the new top of the stack the active view controller. If the view controller at the top of the stack is the root view controller, this method does nothing. In other words, you cannot pop the last item on the stack.[UINavigationController popViewControllerAnimated]

In addition to displaying the view associated with the new view controller at the top of the stack, this method also updates the navigation bar and tool bar accordingly. In iOS 3.0 and later, the contents of the built-in navigation toolbar are updated to reflect the toolbar items of the new view controller. For information on how the navigation bar is updated, see “Updating the Navigation Bar.”

UINavigationController popViewControllerAnimated example.
// locally store the navigation controller since
// self.navigationController will be nil once we are popped
UINavigationController *navController = self.navigationController;

// retain ourselves so that the controller will still exist once it's popped off
[[self retain] autorelease];

// Pop this controller and replace with another
[navController popViewControllerAnimated:NO];
[navController pushViewController:someViewController animated:NO];

Example of [UINavigationController popViewControllerAnimated].
MyEditViewController *mevc = [[MYEditViewController alloc] initWithGizmo: gizmo];

    UINavigationController *navController = self.navigationController;     
    [[self retain] autorelease];

    [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration: 0.7];
    [UIView setAnimationTransition:<#UIViewAnimationTransitionCurlDown#> forView:navController.view cache:NO];

    [navController popViewControllerAnimated:NO];
    [navController pushViewController:mevc animated:NO];

    [UIView commitAnimations];

UINavigationController popViewControllerAnimated example.
    [UIView  beginAnimations:nil context:nil];
    [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDuration:0.75];
    [self.navigationController popViewControllerAnimated:NO];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.navigationController.view cache:NO];
    [UIView commitAnimations];

End of UINavigationController popViewControllerAnimated example article.

UINavigationController popToViewController example in Objective C (iOS).


UINavigationController popToViewController

Pops view controllers until the specified view controller is at the top of the navigation stack.

- (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated

Parameters of [UINavigationController popToViewController]
viewController
The view controller that you want to be at the top of the stack.
animated
Set this value to YES to animate the transition. Pass NO if you are setting up a navigation controller before its view is displayed.

Return Value
An array containing the view controllers that were popped from the stack.

Discussion of [UINavigationController popToViewController]
For information on how the navigation bar is updated, see “Updating the Navigation Bar.”

UINavigationController popToViewController example.
- (void) popControllersNumber:(int)number
{
    if (number <= 1)
        [[self navigationController] popViewControllerAnimated:YES];
    else
    {
        NSArray* controller = [[self navigationController] viewControllers];
        int requiredIndex = [controller count] - number - 1;
        if (requiredIndex < 0) requiredIndex = 0;
        UIViewController* requireController = [[[self navigationController] viewControllers] objectAtIndex:requiredIndex];
        [[self navigationController] popToViewController:requireController animated:YES];
    }
}

Example of [UINavigationController popToViewController].
TasksViewController *taskViewController = [[TasksViewController alloc] initWithNibName:nil bundle:nil];

if ([navigationController.viewControllers indexOfObject:taskViewController] == NSNotFound)
{
    [navigationController pushViewController:taskViewController animated:animated];
}
else
{
    [navigationController popToViewController:taskViewController animated:animated];
}

UINavigationController popToViewController example.
YourViewController *yourViewController;
for ( UIViewController *viewController in self.navigationController.viewControllers ) {
    if ( [viewController isMemberOfClass:[YourViewController class]] ) {
        yourViewController = (YourViewController*)viewController;
        break;
    }
}

[self popToViewController:yourViewController animated:YES];

End of UINavigationController popToViewController example article.

UINavigationController initWithNavigationBarClass toolbarClass example in Objective C (iOS).


UINavigationController initWithNavigationBarClass toolbarClass

Initializes and returns a newly created navigation controller that uses your custom bar subclasses.

- (instancetype)initWithNavigationBarClass:(Class)navigationBarClass toolbarClass:(Class)toolbarClass

Parameters of [UINavigationController initWithNavigationBarClass toolbarClass]
navigationBarClass
Specify the custom UINavigationBar subclass you want to use, or specify nil to use the standard UINavigationBar class.
toolbarClass
Specify the custom UIToolbar subclass you want to use, or specify nil to use the standard UIToolbar class.

Return Value of [UINavigationController initWithNavigationBarClass toolbarClass]
The initialized navigation controller object or nil if there was a problem initializing the object.

Discussion of [UINavigationController initWithNavigationBarClass toolbarClass]
Use this initialization method if you want to use custom navigation bar or toolbar subclasses with the navigation controller. If you use this method, you are responsible for adding a root view controller before presenting the navigation controller onscreen.

UINavigationController initWithNavigationBarClass toolbarClass example.
// This code assumes `MyCustomNavigationBar` is the name of your custom subclass, and that `viewController` is a UIViewController object created earlier.

// To create the containing navigation controller
UINavigationController *navigationController = [[UINavigationController alloc] initWithNavigationBarClass:[MyCustomNavigationBar class] toolbarClass:[UIToolbar class]];

// To set the root view controller in the navigation controller
navigationController.viewControllers = @[viewController];

Example of [UINavigationController initWithNavigationBarClass toolbarClass].
Like this:

UINavigationController *navigationController = [[UINavigationController alloc] initWithNavigationBarClass:[MyNavigationBar class] toolbarClass:[UIToolbar class]];

[navigationController setViewControllers:@[yourRootViewController] animated:NO];

UINavigationController initWithNavigationBarClass toolbarClass example.
e.g.

@interface MyBar : UINavigationBar
@end

@implementation MyBar
.... //like any UIView
@end
UINavigationController *navi = [[UINavigationController alloc] initWithNavigationBarClass:[MyBar class] toolbarClass:nil];
instead of initWithRootViewController

Sample

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
    self.mainViewController = [[FDMainViewController alloc] initWithNibName:@"FDMainViewController_iPhone" bundle:nil];
} else {
    self.mainViewController = [[FDMainViewController alloc] initWithNibName:@"FDMainViewController_iPad" bundle:nil];
}

UINavigationController *navi = [[UINavigationController alloc] initWithNavigationBarClass:[UINavigationBar class] toolbarClass:nil];
navi.viewControllers = @[self.mainViewController];
self.window.rootViewController = navi;
[self.window makeKeyAndVisible];
return YES;
}

End of UINavigationController initWithNavigationBarClass toolbarClass example article.

Saturday, June 8, 2013

UINavigationController viewControllers example in Objective C (iOS).


UINavigationController viewControllers

The view controllers currently on the navigation stack.

@property(nonatomic, copy) NSArray *viewControllers

Discussion of [UINavigationController viewControllers]
The root view controller is at index 0 in the array, the back view controller is at index n-2, and the top controller is at index n-1, where n is the number of items in the array.

Assigning a new array of view controllers to this property is equivalent to calling the setViewControllers:animated: method with the animated parameter set to NO.

UINavigationController viewControllers example.
UINavigationControllers have a property called viewControllers as you have stated above. Since this is an array of View Controllers, referencing a specific view controller in this hierarchy is no different than accessing any other object in an array.

UIViewController *theControllerYouWant = [self.navigationController.viewControllers objectAtIndex:(theIndexOfYourViewController)];
In addition check out the View Controller's Programming Guide for iOS specifically the section called 'Modifying the Navigation Stack'.

Example of [UINavigationController viewControllers].
NSMutableArray *array = [[NSMutableArray alloc] initWithArray:self.navigationController.viewControllers];
[array removeObjectAtIndex:1];

self.navigationController.viewControllers = array;
Or just use

[self.navigationController setViewControllers:array animated:NO];

UINavigationController viewControllers example.
Pretty Simple, when about to push the thirdViewController inseat of doing a simple pushViewController do this:

NSArray * viewControllers = [self.navigationController viewControllers];
NSArray * newViewControllers = [NSArray arrayWithObjects:[viewControllers objectAtIndex:0], [viewControllers objectAtIndex:1], thirdController,nil];
[self.navigationController setViewControllers:newViewControllers];
where [viewControllers objectAtIndex:0] and [viewControllers objectAtIndex:1] are your rootViewController and your FirstViewController.

End of UINavigationController viewControllers example article.

UINavigationController setToolbarHidden animated example in Objective C (iOS).


UINavigationController setToolbarHidden animated

Changes the visibility of the navigation controller’s built-in toolbar.

- (void)setToolbarHidden:(BOOL)hidden animated:(BOOL)animated

Parameters
hidden
Specify YES to hide the toolbar or NO to show it.
animated
Specify YES if you want the toolbar to be animated on or off the screen.

Discussion of [UINavigationController setToolbarHidden animated]
You can use this method to animate changes to the visibility of the built-in toolbar.

Calling this method with the animated parameter set to NO is equivalent to setting the value of the toolbarHidden property directly. The toolbar simply appears or disappears depending on the value in the hidden parameter.

UINavigationController setToolbarHidden animated example.
- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setToolbarHidden:NO animated:animated];
    [super viewWillAppear:animated];
}
To hide toolbar:

- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setToolbarHidden:YES animated:animated];
    [super viewWillAppear:animated];
}

Example of [UINavigationController setToolbarHidden animated].
//set up the toolbar
[self.navigationController setToolbarHidden:NO animated:NO];
[self.navigationController.toolbar setBarStyle:UIBarStyleBlackOpaque];  //for example

//set the toolbar buttons
 [self setToolbarItems:[NSArray arrayWithObjects:button1, button2, nil]];  

UINavigationController setToolbarHidden animated example.
- (void)viewDidAppear:(BOOL)animated {
    [[self tableView] reloadData];

    [[self navigationController] setToolbarHidden: NO animated:YES];   
    UIBarButtonItem * logoutButton = [[[UIBarButtonItem alloc] initWithTitle:@"Log out" style:UIBarButtonItemStylePlain target:self action:@selector(logOut:)]autorelease];
    NSMutableArray * arr = [NSMutableArray arrayWithObjects:logoutButton, nil];
    [self setToolbarItems:arr animated:YES];

    [super viewDidAppear:animated];
}

End of UINavigationController setToolbarHidden animated example article.

UINavigationController setToolbarHidden example in Objective C (iOS).


UINavigationController setToolbarHidden

Changes the visibility of the navigation controller’s built-in toolbar.

- (void)setToolbarHidden:(BOOL)hidden animated:(BOOL)animated

Parameters
hidden
Specify YES to hide the toolbar or NO to show it.
animated
Specify YES if you want the toolbar to be animated on or off the screen.

Discussion of [UINavigationController setToolbarHidden]
You can use this method to animate changes to the visibility of the built-in toolbar.

Calling this method with the animated parameter set to NO is equivalent to setting the value of the toolbarHidden property directly. The toolbar simply appears or disappears depending on the value in the hidden parameter.

UINavigationController setToolbarHidden example.
- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setToolbarHidden:NO animated:animated];
    [super viewWillAppear:animated];
}
To hide toolbar:

- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setToolbarHidden:YES animated:animated];
    [super viewWillAppear:animated];
}

Example of [UINavigationController setToolbarHidden].
//set up the toolbar
[self.navigationController setToolbarHidden:NO animated:NO];
[self.navigationController.toolbar setBarStyle:UIBarStyleBlackOpaque];  //for example

//set the toolbar buttons
 [self setToolbarItems:[NSArray arrayWithObjects:button1, button2, nil]];  

UINavigationController setToolbarHidden example.
- (void)viewDidAppear:(BOOL)animated {
    [[self tableView] reloadData];

    [[self navigationController] setToolbarHidden: NO animated:YES];   
    UIBarButtonItem * logoutButton = [[[UIBarButtonItem alloc] initWithTitle:@"Log out" style:UIBarButtonItemStylePlain target:self action:@selector(logOut:)]autorelease];
    NSMutableArray * arr = [NSMutableArray arrayWithObjects:logoutButton, nil];
    [self setToolbarItems:arr animated:YES];

    [super viewDidAppear:animated];
}

End of UINavigationController setToolbarHidden example article.

UINavigationController setNavigationBarHidden example in Objective C (iOS).


UINavigationController setNavigationBarHidden

Sets whether the navigation bar is hidden.

- (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated

Parameters
hidden
Specify YES to hide the navigation bar or NO to show it.
animated
Specify YES if you want to animate the change in visibility or NO if you want the navigation bar to appear immediately.

Discussion of [UINavigationController setNavigationBarHidden]
For animated transitions, the duration of the animation is specified by the value in the UINavigationControllerHideShowBarDuration constant.

UINavigationController setNavigationBarHidden example.
- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:YES animated:animated];
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [self.navigationController setNavigationBarHidden:NO animated:animated];
    [super viewWillDisappear:animated];
}

Example of [UINavigationController setNavigationBarHidden].
- (void) viewWillDisappear:(BOOL)animated
{
    if (self.navigationController.topViewController != self)
    {
        [self.navigationController setNavigationBarHidden:NO animated:animated];
    }

    [super viewWillDisappear:animated];
}

UINavigationController setNavigationBarHidden example.
For the UINavigationController:

[UINavigationBar beginAnimations:@"NavBarFade" context:nil];
self.navigationController.navigationBar.alpha = 1;
[self.navigationController setNavigationBarHidden:YES animated:NO]; //Animated must be NO!
[UINavigationBar setAnimationCurve:UIViewAnimationCurveEaseIn];
[UINavigationBar setAnimationDuration:1.5];
self.navigationController.navigationBar.alpha = 0;
[UINavigationBar commitAnimations];
For the UITabBarController:

[UITabBar beginAnimations:@"TabBarFade" context:nil];
self.tabBarController.tabBar.alpha = 1;
[self.tabBarController.tabBar setHidden:YES];
[UITabBar setAnimationCurve:UIViewAnimationCurveEaseIn];
[UITabBar setAnimationDuration:1.5];
self.tabBarController.navigationBar.alpha = 0;
[UITabBar commitAnimations];

End of UINavigationController setNavigationBarHidden example article.

UINavigationController topViewController example in Objective C (iOS).


UINavigationController topViewController

The view controller at the top of the navigation stack. (read-only)

@property(nonatomic, readonly, retain) UIViewController *topViewController

UINavigationController topViewController example.
- (void)applicationDidFinishLaunching:(UIApplication *)application {

    RootViewController *rootViewController = (RootViewController *)[navigationController topViewController];
    rootViewController.managedObjectContext = self.managedObjectContext;

    // Configure and show the window
    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];
}

Example of [UINavigationController topViewController].
Try topViewController instead of visibleViewController.

FirstViewController *fVC = [navController topViewController];

UINavigationController topViewController example.
Implement the UINavigationControllerDelegate method:

 - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
and query it to find out the currently displayed view controller:

 navigationController.topViewController
This is the one you're coming from.


End of UINavigationController topViewController example article.

UINavigationController toolbarHidden example in Objective C (iOS).


UINavigationController toolbarHidden

A Boolean indicating whether the navigation controller’s built-in toolbar is visible.

@property(nonatomic,getter=isToolbarHidden) BOOL toolbarHidden

Discussion of [UINavigationController toolbarHidden]
If this property is set to YES, the toolbar is not visible. The default value of this property is YES.

UINavigationController toolbarHidden example.
To show toolbar in new view controller just add this:

- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setToolbarHidden:NO animated:animated];
    [super viewWillAppear:animated];
}
To hide toolbar:

- (void)viewWillAppear:(BOOL)animated
{
    [self.navigationController setToolbarHidden:YES animated:animated];
    [super viewWillAppear:animated];
}

Example of [UINavigationController toolbarHidden].
-(id)initWithNibName:(NSString*)name bundle:(NSBundle*)bundle;
{
  self = [super initWithNibName:name bundle:bundle];
  if (self) {
    self.title = @"My Title";
    NSArray* toolbarItems = [NSArray arrayWithObjects:
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
                                                      target:self
                                                      action:@selector(addStuff:)],
        [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSearch
                                                      target:self
                                                      action:@selector(searchStuff:)],
        nil];
    [toolbarItems makeObjectsPerformSelector:@selector(release)];
    self.toolbarItems = toolbarItems;
    self.navigationController.toolbarHidden = NO;
  }
  return self;
}

UINavigationController toolbarHidden example.
- (void)viewDidLoad { 
    [super viewDidLoad]; 
 
    self.title = @"My View Controller"; 
    // hide the navigation bar 
    // use setToolbarHidden:animated: if you need animation 
    self.navigationController.toolbarHidden = NO; 
}  

End of UINavigationController toolbarHidden example article.

UINavigationController navigationBarHidden example in Objective C (iOS).


UINavigationController navigationBarHidden

A Boolean value that determines whether the navigation bar is hidden.

@property(nonatomic, getter=isNavigationBarHidden) BOOL navigationBarHidden

Discussion of [UINavigationController navigationBarHidden]
If YES, the navigation bar is hidden. The default value is NO. Setting this property does not animate the hiding or showing of the navigation bar; use setNavigationBarHidden:animated: for that purpose.

UINavigationController navigationBarHidden example.
- (void)viewDidLoad
{
    [super viewDidLoad];
     self.title = @"My Title";
     self.navigationController.navigationBarHidden = YES; //YES : 숨기기, NO : 보이기
}

Example of [UINavigationController navigationBarHidden].
CATransition *transition = [CATransition animation];
transition.duration = kAnimationDuration;
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
transition.type = kCATransitionPush;
transition.subtype = kCATransitionFromTop;
transition.delegate = self;
[self.navigationController.view.layer addAnimation:transition forKey:nil];

self.navigationController.navigationBarHidden = NO;
[self.navigationController pushViewController:tableViewController animated:YES];

UINavigationController navigationBarHidden example.
Use this in first view controller:

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[self navigationController] setNavigationBarHidden:YES animated:animated];
}

End of UINavigationController navigationBarHidden example article.

UINavigationController navigationBar example in Objective C (iOS).


UINavigationController navigationBar

The navigation bar managed by the navigation controller. (read-only)

@property(nonatomic, readonly) UINavigationBar *navigationBar

Discussion of [UINavigationController navigationBar]
It is permissible to modify the barStyle or translucent properties of the navigation bar but you must never change its frame, bounds, or alpha values directly. To show or hide the navigation bar, you should always do so through the navigation controller by changing its navigationBarHidden property or calling the setNavigationBarHidden:animated: method.

UINavigationController navigationBar example.
If you really want the navigation bar and you're targeting 3.2 and up I would recommend to attach an UITapGestureRecognizer to the navigationBar.

- (void)viewDidLoad {
    UITapGestureRecognizer* tapRecon = [[UITapGestureRecognizer alloc]
              initWithTarget:self action:@selector(navigationBarDoubleTap:)];
    tapRecon.numberOfTapsRequired = 2;
    [navController.navigationBar addGestureRecognizer:tapRecon];
    [tapRecon release];
}

- (void)navigationBarDoubleTap:(UIGestureRecognizer*)recognizer {
    [tableView setContentOffset:CGPointMake(0,0) animated:YES];
}

Example of [UINavigationController navigationBar].
// Initialise the navigation controller with the first view controller as its root view controller
navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];

// Add your code here
[navigationController.navigationBar setBarStyle:UIBarStyleBlack];
// I have commented out the set translucent attribute, as it has some interesting effects.  Try uncommenting it :).
// [navigationController.navigationBar setTranslucent:YES];
[navigationController.navigationBar setTintColor:[UIColor redColor]];

// If you wish to hide the navigation controller
// Note: We are able to alternatively hide or show the navigation bar by using
// [self.navigationController setNavigationBarHidden:YES] in our viewWillAppear method
// within the specific UIViewController that we wish to hide/show the navigation bar
[navigationController setNavigationBarHidden:YES];

// Navigation controller has copy of view controller, so release our copy
[rootViewController release];

UINavigationController navigationBar example.
- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title = @"My Title";
    self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:255.0/255
                                                                                  green:10.0/255 blue:100.0/255 alpha:1];
}

- (void)viewDidLoad
{
   super viewDidLoad];
   self.title = @"My Title";
   self.navigationController.navigationBar.barStyle = UIBarStyleBlack; //스타일 적용
   self.navigationController.navigationBar.translucent = YES; // 반투명 효과 주기
}

End of UINavigationController navigationBar example article.