简体   繁体   中英

Remove previous view controller text from back button

I would like to remove the "previous view controller's text" from my back button. As you can see on the example, i have "corals anatomy" that I would like to remove and have only "Back" if possible, even removing the chevron.

I have tried many like:

    navigationItem.backBarButtonItem?.title = "Test"
    navigationItem.backBarButtonItem = UIBarButtonItem(title: "Test", style: .Plain, target: nil, action: nil)
    navigationItem.leftBarButtonItem?.title = "Test"

None of these worked.

Any ideas?

You can customise the backbar buttonItem by setting the leftBarButtonItem of a navigationItem in viewDidLoad() like below

override func viewDidLoad() {
        super.viewDidLoad()

        let backButton:UIBarButtonItem = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Done, target: self, action: "backBtnAction:")
        self.navigationItem.leftBarButtonItem = backButton
    }

    @IBAction func backBtnAction(sender:UIBarButtonItem)
    {
       //your code here
    }

You can try like this:

let newBackButton: UIBarButtonItem = UIBarButtonItem(title: "Back", style: .Plain, target: self, action: "btnBack")
self.navigationItem.backBarButtonItem = newBackButton

//handle the back click 

func btnBackClicked() {
   self.navigationController?.popToRootViewControllerAnimated(true)
}

I use Objective-C:

UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:IS_IOS7?@"":@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];

[controller.navigationItem setBackBarButtonItem:backButton];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM