How to change text on a back button

前端 未结 20 2136
无人及你
无人及你 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:41

    My solution was to set title when the view controller is pushed to navigation stack and reset it by use of delegate method before pushed vc closes:

    So I put the title change in calling view controller when I push the other view controller like:

    self.pushedVC = [self.storyboard instantiateViewControllerWithIdentifier:@"pushedVCIdentifier"];
    self.pushedVC.delegate = self;   
    [self.navigationController pushViewController:self.pushedVC animated:YES];
    self.title = @"Back";
    

    and in delegate callback function (which I invoke in viewWillDissapear):

    -(void)pushedVCWillClose:(PushedVC *)sender
    {
        self.title = @"Previous Title";
    }
    

提交回复
热议问题