gpt4 book ai didi

swift - UIBarButtonItem 设置后未突出显示

转载 作者:行者123 更新时间:2023-11-30 11:38:37 25 4
gpt4 key购买 nike

我声明了两个 UIBarButtonItem,btnEdit 和 btnSave。最初我在 viewDidLoad 中设置 btnEdit 。如果用户点击 btnEdit 我想将 btnSave 设置为 rightBarButtonItem 并在点击 btnSave 时设置 btnEdit 作为 rightBarButtonItem。

它工作正常,我可以点击它,但第一次点击按钮消失/不处于突出显示状态。附图片。我如何使其具有正常状态?

var btnEdit : UIBarButtonItem!
var btnSave : UIBarButtonItem!

@objc func btnEditTapped (){
textFieldViewNote.isEditable = true
navigationItem.rightBarButtonItem = btnSave
}


@objc func btnSaveTapped (){
textFieldViewNote.isEditable = false
navigationItem.rightBarButtonItem = btnEdit

}



override func viewDidLoad() {
super.viewDidLoad()
btnSave = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(btnSaveTapped))
btnEdit = UIBarButtonItem(barButtonSystemItem: .edit, target: self, action: #selector(btnEditTapped))
navigationItem.rightBarButtonItem = btnEdit

}

After loading VC - Edit in normal state

After tapping on edit - Save btn in normal State

Edit faded tapping on save barbutton

最佳答案

下面是固定代码

 class ViewController: UIViewController {

var btnEdit : UIBarButtonItem!
var btnSave : UIBarButtonItem!

@objc func btnEditTapped (){
btnSave = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(btnSaveTapped));

navigationItem.rightBarButtonItem = btnSave

}


@objc func btnSaveTapped (){
btnEdit = UIBarButtonItem(barButtonSystemItem: .edit, target: self, action: #selector(btnEditTapped)); navigationItem.rightBarButtonItem = btnEdit


}



override func viewDidLoad() {
super.viewDidLoad()
btnSave = UIBarButtonItem(barButtonSystemItem: .save, target: self, action: #selector(btnSaveTapped))
btnEdit = UIBarButtonItem(barButtonSystemItem: .edit, target: self, action: #selector(btnEditTapped))
navigationItem.rightBarButtonItem = btnEdit

}
}

关于swift - UIBarButtonItem 设置后未突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49466187/

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