How to hide the “back” button in UINavigationController?

前端 未结 14 2373
盖世英雄少女心
盖世英雄少女心 2020-12-04 07:09

Do you know how to hide the \'back\' button in a UINavigationController? Also, how to show it back, but I guess that\'s very similar to hiding it...

Just like the ma

14条回答
  •  [愿得一人]
    2020-12-04 07:55

    Just to clarify existing answers: the hidesBackButton property is the right answer, but it isn't clear in many answers what self refers to. Basically you should set self.navigationItem.hidesBackButton = YES in the view controller that is about to get pushed (or just got pushed) onto the UINavigationController.

    In other words, say I have a UINavigationController named myNavController. I want to put a new view on it, and when I do I don't want the back button to show anymore. I could do something like:

    UIViewController *newVC = [[UIViewController alloc] init];
    //presumably would do some stuff here to set up the new view controller
    newVC.navigationItem.hidesBackButton = YES;
    [myNavController pushViewController:newVC animated:YES];
    

    When the code finishes, the view controlled by newVC should now be showing, and no back button should be visible.

提交回复
热议问题