How to change text on a back button

前端 未结 20 2063
无人及你
无人及你 2020-11-29 17:24

By default the back button uses as a text on it a title of a viewcontroller. Can I change text on the back button without changing a title of a view controller? I need this

20条回答
  •  时光取名叫无心
    2020-11-29 17:48

    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";

提交回复
热议问题