我正在寻找一个小问题的解决方案, 我已经在单元格类中声明了一个按钮:
class MyCell: UICollectionViewCell {
@IBOutlet weak var button: UIButton!
}
但现在我试图从我的主类访问按钮变量,如果加载 View ,按钮应该隐藏,并且在几个函数中按钮应该再次突出显示:
class mainClassController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
// here I try to create reference to the button variable
...
}
最佳答案
我想这应该可行(仅在 Playground 上测试)
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
}
关于ios - 如何在不继承的情况下访问另一个类的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35994684/