我已经在MainViewController
中创建了一个导航栏按钮
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Save", style: .plain, target: self, action: #selector(presentPopup))
}
@objc func presentPopup() {
let popupVC = PopupViewController()
popupVC.modalPresentationStyle = .overCurrentContext
present(popupVC, animated: true, completion: nil)
}
它显示用于保存主视图内容的弹出表单(包含"保存"按钮).我想让这个"保存"按钮(在PopupViewController
):(1)将S导航栏按钮的标题改为"已保存";(2)禁用该按钮.
到目前为止,我在PopupViewController
人中有以下几点:
let popupBox: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
let button: UIButton = {
let view = UIButton()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
override func viewDidLoad() {
super.viewDidLoad()
self.definesPresentationContext = true
view.backgroundColor = .clear
view.addSubview(popupBox)
// configure popupBox
view.addSubview(button)
// configure button
button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
}
@objc func buttonAction(_ sender: UIButton) {
// save main VC's contents
// change title of main VC's nav button - WHAT GOES HERE?
// disable main VC's nav button - WHAT GOES HERE?
self.dismiss(animated: true) // dismiss popup
}
我应该在按钮的操作中添加什么来完成我想做的事情?