Sunday, June 9, 2013

UINavigationBar pushNavigationItem animated example in Objective C (iOS).

UINavigationBar pushNavigationItem animated

Pushes the given navigation item onto the receiver’s stack and updates the navigation bar.

- (void)pushNavigationItem:(UINavigationItem *)item animated:(BOOL)animated

The navigation item to push on the stack.
YES if the navigation bar should be animated; otherwise, NO.

Discussion of [UINavigationBar pushNavigationItem animated]
Pushing a navigation item displays the item’s title in the center on the navigation bar. The previous top navigation item (if it exists) is displayed as a back button on the left side of the navigation bar. If the new top item has a left custom view, it is displayed instead of the back button.

UINavigationBar pushNavigationItem animated example.
On your navigationbar reference you could invoke the two methods:

- (void)pushNavigationItem:(UINavigationItem *)item animated:(BOOL)animated
- (UINavigationItem *)popNavigationItemAnimated:(BOOL)animated
In your custom view controller class write something like this:

self.navigationItem.leftBarButtonItem = yourButton;
self.navigationItem.rightBarButtonItem = yourSecondButton;
So you could write something like this:

[myNavBarReference pushNavigationItem:self.navigationItem animated:NO];

Example of [UINavigationBar pushNavigationItem animated].
Try using the navigation item's title property for this:

UINavigationItem *item = [[[UINavigationItem alloc] initWithTitle:@"Login"] autorelease];
[yourNavigationBar pushNavigationItem:item animated:NO];

UINavigationBar pushNavigationItem animated example.
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] 
initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self 
                        UINavigationItem *navigationItem = [[UINavigationItem alloc] 
                        navigationItem.rightBarButtonItem = buttonItem;
                        [navigationItem setLeftBarButtonItem:nil];
                        [self.sideNavigationBarCtrl pushNavigationItem:navigationItem 
                        [navigationItem release];
                        [buttonItem release];

End of UINavigationBar pushNavigationItem animated example article.