1

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..!

4

1 回答 1

3

尝试从 rootviewcontroller 类 (photoController) viewDidLoad 方法添加 UIBarButtonItem。

self.navigationItem.rightBarButtonItem =  [[UIBarButtonItem alloc] initWithTitle: @"Back"
                                                           style: UIBarButtonItemStyleBordered
                                                          target: navController
                                                          action: @selector(onBack)];
于 2012-04-11T12:35:15.367 回答