如何在没有inheritance的情况下从另一个类访问属性
我正在寻找一个小问题的解决scheme,我宣布了一个button,我细胞类:
class MyCell: UICollectionViewCell { @IBOutlet weak var button: UIButton! }
但现在我试图从我的主类访问buttonvariables,如果视图被加载的button应该隐藏,并在几个function的button应该再次突出显示:
class mainClassController: UICollectionViewController, UICollectionViewDelegateFlowLayout { // here I try to create reference to the button variable ... }
我想这应该(只在运动场testing)
class MyCell: UICollectionViewCell { @IBOutlet var button: UIButton! } var myCell = MyCell() //Generate one object of your class, just put this outside any class class main: UICollectionViewController, UICollectionViewDelegateFlowLayout{ var cellButton = myCell.button }