更改导航控制器的后退按钮

时间:2017-03-18 12:38:09

标签: swift swift3 uikit

我有这段代码:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) 
{
        let controller = SectionsController()
        self.navigationController?.pushViewController(controller, animated: true)
}

在我班上:

class HomeController: UITabBarController,UITableViewDataSource,UITableViewDelegate, AddingProtocoleDelegate 

我想将后退按钮标题更改为"Back"

我在sectionController viewDidLoad:

中试过这个
        self.navigationItem.backBarButtonItem?.title = "Back"
        self.navigationController?.navigationBar.backItem?.title = "Back"
        self.navigationController?.navigationItem.title = "Back"
        let backButton = UIBarButtonItem(
            title: "Back",
            style: UIBarButtonItemStyle.plain,
            target: nil,
            action: nil
        );
        self.navigationController?.navigationBar.topItem?.backBarButtonItem = backButton;

但任何解决方案都不起作用。

请帮助。

2 个答案:

答案 0 :(得分:1)

后退按钮属于上一个视图控制器,而不是当前在屏幕上显示的控制器。试试这个,看看它是否适合你。

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let backItem = UIBarButtonItem()
backItem.title = "Back"
navigationItem.backBarButtonItem = backItem
}

斯威夫特3:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let backItem = UIBarButtonItem()
backItem.title = "Back"
navigationItem.backBarButtonItem = backItem
}

答案 1 :(得分:0)

使用此@XmlSchema(elementFormDefault=QUALIFIED)