Dinesh
Dinesh

Reputation: 6532

Add UIBarButtonItem to UINavigationController on iphone sdk

I want to add back button on UINavigationController,I am trying Below Code :

EGOPhotoViewController *photoController = [[EGOPhotoViewController alloc] initWithPhotoSource:source];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:photoController];
    navController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    navController.modalPresentationStyle = UIModalPresentationFullScreen;
   // UINavigationBar *my_bar;
    //UINavigationItem *my_item=[[UINavigationItem alloc] initWithTitle:@"test"];
    UIBarButtonItem* button = [[UIBarButtonItem alloc] initWithTitle: @"Back"
                                                               style: UIBarButtonItemStyleBordered
                                                              target: navController
                                                              action: @selector(onBack)];
    //my_item.rightBarButtonItem = button;
    [[navController navigationItem] setRightBarButtonItem:button];
    self.title=@"Gallery";
    [self presentModalViewController:navController animated:YES];

this code output is Below:

enter image description here

code does not add Back Button in UINavigationController.I am adding Code to Back button on UINavigationController,what's Wrong on my code...!

Please any one help me...!

Thanks..!

Upvotes: 1

Views: 3127

Answers (1)

Adam Ivancza
Adam Ivancza

Reputation: 2529

Try to add the UIBarButtonItem from the rootviewcontroller class (photoController) viewDidLoad method.

self.navigationItem.rightBarButtonItem =  [[UIBarButtonItem alloc] initWithTitle: @"Back"
                                                           style: UIBarButtonItemStyleBordered
                                                          target: navController
                                                          action: @selector(onBack)];

Upvotes: 3

Related Questions