Reputation: 745
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?
Upvotes: 0
Views: 447
Reputation: 1
I use Objective-C:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:IS_IOS7?@"":@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
[controller.navigationItem setBackBarButtonItem:backButton];
Upvotes: 0
Reputation: 427
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
}
Upvotes: 3
Reputation: 6112
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)
}
Upvotes: 0