Back button not appearing on UINavigationController

后端 未结 5 568
抹茶落季
抹茶落季 2021-01-05 18:39

I have a UINavigationController setup in my AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSD         


        
相关标签:
5条回答
  • 2021-01-05 19:18

    This happened to me because in my navigation controller's content controller I had set up some navigation controller behavior in viewDidLoad and in another class that inherits from my content controller, and the one that was being presented, i implemented a viewDidLoad as well, and forgot to call [super viewDidLoad] which thereby caused me to override the base class's viewDidLoad where I was setting up my navigation controller buttons. Oooops.

    0 讨论(0)
  • 2021-01-05 19:20

    Using presentModalViewController to show the naviagtionController. Set the navagitionController bar button like so:

    [navigationController.navigationBar.topItem setLeftBarButtonItem:
        [[[UIBarButtonItem alloc] initWithTitle: @"Back" 
                                          style: UIBarButtonItemStylePlain
                                         target: self
                                         action: @selector(dismisstheModal:)] autorelease]];
    
    0 讨论(0)
  • 2021-01-05 19:31

    You must think of the navigation controller as a stack of navigation controllers each controlling one screen full of information. You instantiate the navigation controller with the

    -(id)initWithRootViewController:(UIViewController *)rootViewController
    

    method. You specify the root view controller in this call. Then you add the navigation controller's view as a subview to the window, like you did before.

    If you want to show your second screen you push another view controller on the stack by using

    -(void)pushViewController:detailViewController animated:YES
    

    method.

    0 讨论(0)
  • 2021-01-05 19:33

    Try this:

    DetailViewController *detailViewController = [[DetailViewController alloc] init];
    UIBarButtonItem *back = [[UIBarButtonItem alloc] initWithTitle : @"Back"
                                                             style : UIBarButtonItemStyleDone
                                                            target : nil
                                                            action : nil];
    self.navigationItem.backBarButtonItem = back;
    [self.navigationController pushViewController : detailViewController animated : YES];
    [detailViewController release];
    
    0 讨论(0)
  • 2021-01-05 19:34

    Are you setting self.title in RootViewController? Perhaps the UINavigationController doesn't have any text to put on the back button, so it omits it...?

    Are you setting hidesBackButton = YES or backBarButtonItem = nil in DealViewController, or does it have a different leftBarButtonItem defined?

    0 讨论(0)
提交回复
热议问题