Sunday, June 9, 2013

UINavigationItem setRightBarButtonItem animated example in Objective C (iOS).


UINavigationItem setRightBarButtonItem animated

Sets the custom bar button item, optionally animating the transition to the view.

- (void)setRightBarButtonItem:(UIBarButtonItem *)item animated:(BOOL)animated

Parameters of [UINavigationItem setRightBarButtonItem animated]
item
A custom bar item to display on the right of the navigation bar.
animated
Specify YES to animate the transition to the custom bar item when this item is the top item. Specify NO to set the item immediately without animating the change.

Discussion of [UINavigationItem setRightBarButtonItem animated]
If two navigation items have the same custom left or right bar button items, those bar button items remain stationary during the transition when the navigation item is pushed or popped.

UINavigationItem setRightBarButtonItem animated example.
UINavigationItem *backNavItem = [[UINavigationItem alloc] initWithTitle:@"TESTTEST"];
[backNavItem setRightBarButtonItem:backButton animated:YES];

Example of [UINavigationItem setRightBarButtonItem animated].
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(theEditMethod:)];    
[viewController.navigationItem setLeftBarButtonItem:leftBarButton animated:NO];
[leftBarButton release];

UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(theAddMethod:)];     
[viewController.navigationItem setRightBarButtonItem:rightBarButton animated:NO];
[rightBarButton release];

End of UINavigationItem setRightBarButtonItem animated example article.