gpt4 book ai didi

ios - 如何在 Swift 中设置返回按钮文本

转载 作者:IT老高 更新时间:2023-10-28 12:16:12 27 4
gpt4 key购买 nike

如何删除后退按钮文本。

当前的后退按钮:

< Back

所需的后退按钮:

< AnythingElse

这些都不起作用:

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

最佳答案

后退按钮属于上一个 View Controller ,而不是当前显示在屏幕上的那个。
要修改后退按钮,您应该推送之前更新它,在启动 segue 的 View Controller 上:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let backItem = UIBarButtonItem()
backItem.title = "Something Else"
navigationItem.backBarButtonItem = backItem // This will show in the next view controller being pushed
}

swift 3、4 和 5:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let backItem = UIBarButtonItem()
backItem.title = "Something Else"
navigationItem.backBarButtonItem = backItem // This will show in the next view controller being pushed
}

// in your viewDidLoad or viewWillAppear
navigationItem.backBarButtonItem = UIBarButtonItem(
title: "Something Else", style: .plain, target: nil, action: nil)

关于ios - 如何在 Swift 中设置返回按钮文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28471164/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com