我已经声明了两个UIBarButtonItem,btnEdit和btnSave。最初我在viewDidLoad中设置btnEdit。如果用户点击btnEdit,我想将btnSave设置为rightBarButtonItem,当点击btnSave时,设置btnEdit as 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
答案 0 :(得分:0)
以下是固定代码
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
}
}