Changing the UIBackButtonItem title

前端 未结 14 894
终归单人心
终归单人心 2020-12-04 17:48

I have a navigationController-based app. I want to change the title of the back button for the root view controller. I have tried the following code in the rootViewControlle

14条回答
  •  一整个雨季
    2020-12-04 18:33

    The back button pulls its text from the title of the parent view controller.

    In the parent view controller (the view controller that appears when you tap the back button), set its own title as the desired text on the back button.

    For example, let's say we have a RootViewController class. When we click a cell in its table view, we push an instance of SecondViewController. We want the back button of the SecondViewController instance to read, "Home."

    in the viewDidLoad method of RootViewController.m:

    self.title = @"Home";
    

    in the viewDidLoad method of SecondViewController.m:

    UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem = backButton;
    [backButton release];    
    

    If you want your back button to read, "Back," set the title of the parent view controller to @"Back";

提交回复
热议问题