gpt4 book ai didi

ios - 如何在不继承的情况下访问另一个类的属性

转载 作者:行者123 更新时间:2023-11-30 13:36:39 24 4
gpt4 key购买 nike

我正在寻找一个小问题的解决方案,我已经在单元格类中声明了一个按钮:

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/

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