How to show back button on the RootViewController of the UINavigationController?

前端 未结 4 686
独厮守ぢ
独厮守ぢ 2021-01-08 01:29

Here is my code. I want to put a back button on the opening rootviewController.

- (void)selectSurah:(id)sender {

    SurahTableViewController * surahTableVi         


        
4条回答
  •  没有蜡笔的小新
    2021-01-08 01:45

    Appearance and behavior of a back button in a UINavigationController relies on interaction between a stack of UINavigationControllers. Putting a back button on the first controller breaks this convention, there's nothing to go back to, which is why your code isn't working.

    You'll need to manually add UIBarButtonItem to the title bar code like:

    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:self action:@selector(back:)];
    

    If you truly want it to look like a back button, you'll need to manually create the UIBarButtonItem with an image that mirrors the back button.

    Another suggestion though, as it looks like you are attempting to use a back button to dismiss a modal view controller, I'd stick with something more conventional like a "Close" or "Done" button to close the modal view controller. A back button is really more appropriate for navigating a stack of UINavigationControllers.

提交回复
热议问题