ios - 如何在 Swift 中更改 UINavigationBar 中的编辑/完成按钮标题

标签 ios swift

<分区>

我在我的表格 View 中显示一个 editButtonItem,但我需要将编辑和完成的文本更改为更改和取消。到目前为止,我找到的所有示例都在 Objective-C 中……我需要 Swift 语法。

我在 viewDidLoad 函数中有以下...

self.navigationItem.leftBarButtonItem = self.editButtonItem()

...显示标准的编辑/完成按钮项。

最佳答案

您想使用setEditing 方法

override func setEditing (editing:Bool, animated:Bool)
{
   super.setEditing(editing,animated:animated)
   self.editButtonItem.title = editing ? "Cancel" : "Change"
 }

并在 viewDidLoad() 中添加以下行

 self.navigationItem.leftBarButtonItem!.title = "Change"

关于ios - 如何在 Swift 中更改 UINavigationBar 中的编辑/完成按钮标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37254045/

相关文章:

ios - Swift - 约束 - 动态标签宽度

ios - 自定义 View - 在 "required init?(coder aDecoder: NSCoder)"方法中崩溃

swift - @available 重命名需要帮助

swift - SpriteKit : Add Multiple SKSpriteNodes To The Scene

iphone - MKMapview 变换仅旋转 map 内容

ios - ios 模拟器上的 flutter debug 不起作用

ios - 在 UITableView 的自定义单元格中引用 UITextFields

ios - 如何为 UIView 关键帧动画设置动画曲线 (`func UIView.animateKeyframes()` )

swift - 使用SPM将Xcode环境变量添加到项目目录

swift - 在 iOS16.4 中 TextField 内的电子邮件提示呈现蓝色