如何隐藏其他类的按钮

时间:2017-09-09 22:10:45

标签: swift uibarbuttonitem

所以我有一个带有两个按钮的navBar的视图。我想知道是否有可能从另一个班级我可以选择我想要那些按钮显示? 我的意思是,当你在RecentsVC中并点击发送新消息时,我可以将你带到一个名为Contacts的视图。那个视图有两个按钮,其中一个我想要隐藏。因此,在IBAction中单击以发送新消息,我想设置属性以隐藏其中一个按钮。

1 个答案:

答案 0 :(得分:1)

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

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
    }
}
相关问题