如何删除后退按钮的文本。

当前返回按钮:

<返回

需要的后退按钮:

< 其他任何东西

这些都没有奏效:

self.navigationItem.backBarButtonItem?.title = "Back"
self.backItem?.title = ""
self.navigationController?.navigationBar.backItem?.title = ""
self.navigationItem.backBarButtonItem?.title = ""
self.navigationController?.navigationItem.backBarButtonItem?.title="Back"
self.navigationController?.navigationBar.backItem?.title = ""
self.navigationController?.navigationItem.backBarButtonItem?.title

当前回答

Swift 4 -在按任何视图控制器之前配置后退按钮

// if you want to remove the text
navigationItem.backBarButtonItem = UIBarButtonItem()

// if you want to modify the text to "back"
navigationItem.backBarButtonItem = UIBarButtonItem(title: "back", style: .plain, target: nil, action: nil)

其他回答

有两种不同的方法来植入那部分,  

1.

navigationItem.backButtonTitle = "Title Goes Here"

(5)迅速

  2.

 let backButton = UIBarButtonItem()

backButton。title = "标题在这里" self.navigationController .navigationBar.topItem ?。backBarButtonItem = backButton

 

斯威夫特4

在我的案例中,解决方案是在移动到子视图控制器之前清除主视图控制器的导航项。如果再次显示,请重新设置

MasterController

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    navigationItem.title = "Master Title"
}

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    navigationItem.title = ""
}

这就是我如何推送一个UIViewController并清除子控制器中的后栏按钮项:

MasterController

let childController = ChildController(collectionViewLayout: UICollectionViewFlowLayout())
childController.navigationItem.backBarButtonItem?.title = ""
navigationController?.pushViewController(childController, animated: true)

虽然这些答案解决了问题,但这可能是一些有用的

class MainNavigatioController: UINavigationController {

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        // first
        let backItem = UIBarButtonItem()
        backItem.title = "رجوع"
        self.viewControllers.last?.navigationItem.backBarButtonItem = backItem
        // then
        super.pushViewController(viewController, animated: animated)

    }

}

back按钮属于前一个视图控制器,而不是当前显示在屏幕上的那个。 要修改后退按钮,你应该在按之前更新它,添加viewdidload:

斯威夫特4:

self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: self, action: nil)

Swift 4 -在按任何视图控制器之前配置后退按钮

// if you want to remove the text
navigationItem.backBarButtonItem = UIBarButtonItem()

// if you want to modify the text to "back"
navigationItem.backBarButtonItem = UIBarButtonItem(title: "back", style: .plain, target: nil, action: nil)