作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我声明了两个 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
最佳答案
下面是固定代码
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/
有没有一种方法可以“标记”对象的属性,使它们在反射中“突出”? 例如: class A { int aa, b; string s1, s2; public int AA
我是一名优秀的程序员,十分优秀!