最近突然项目出现了个导航bug,而且只有最新系统才会出现,很怪异!
经过查看代码,并没有找到病因,最后怀疑是系统的bug,结果发现:直接用系统的UIBarButtonItem.init(title: "注册", style: .plain, target: self, action: #selector(btnClick))创建的item会出现这种情况,只有 UIBarButtonItem.init(customView: btn)方法创建的现实正常
事例如下:
func initNavRightButton() {
let btn = UIButton.init()
btn.addTarget(self, action: #selector(btnClick), for: UIControlEvents.touchUpInside)
btn.setTitle("注册", for: UIControlState.normal)
btn.setTitleColor(UIColor.black, for: UIControlState.normal)
self.navigationItem.rightBarButtonItem = UIBarButtonItem.init(customView: btn)
// let rightBarButtonItem:UIBarButtonItem = UIBarButtonItem.init(title: "注册", style: .plain, target: self, action: #selector(btnClick))
// rightBarButtonItem.tintColor = UIColor.black
// self.navigationItem.rightBarButtonItem = rightBarButtonItem
}
@objc func btnClick() -> Void {
let third = ThirdViewController()
self.navigationController?.pushViewController(third, animated: true)
}
新系统用下面注释的方法运行结果如图:
首次进入
屏幕快照 2018-02-26 下午4.40.15.png
进入注册页面后再返回
屏幕快照 2018-02-26 下午4.39.58.png
网友评论