gpt4 book ai didi

swift - 如何隐藏另一个类的按钮

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

所以我有一个 View ,它有一个带两个按钮的导航栏。我想知道是否可以从另一个类(class)选择是否要显示这些按钮?我的意思是,当您在 RecentsVC 中并单击以发送新消息时,我会将您带到名为“联系人”的 View 。该 View 有两个按钮,我想隐藏其中一个。因此,在用于单击以发送新消息的 IBAction 中,我想设置属性以隐藏其中一个按钮。

最佳答案

Contacts 中有一个 bool 变量,并在 RecentsVC 类的 prepare(for segue: ) 方法中设置该变量的值.然后使用该 bool 值来测试 Contacts 是否应该隐藏导航栏按钮项目。

class RecentsVC: UIViewController {        

override func prepare(for segue: UIStoryboardSegue, sender: AnyObject?) {
if(segue.identifier == "sendMessage") { // If there's only one segue from this view controller, you can remove this line
let vc = segue.destination as! Contacts
vc.buttonIsHidden = true
} // If you removed the if, don't forget to remove this, too
}
}

class Contacts: UIViewController {

var buttonIsHidden: Bool?

override func viewDidLoad() {
super.viewDidLoad()

if buttonIsHidden == true {
self.navigationItem.leftBarButtonItem = nil
}
}
}

关于swift - 如何隐藏另一个类的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46135557/

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