swift - 在另一个类中使用一个类中的变量
问题描述
我有两个班级:CollectionCell
和ViewController
。
第一个类用于 Collection View Cell(我在其中放置了一个按钮)。在CollectionCell
课堂上,我需要为这个按钮连接插座:@IBOutlet weak var firstPercent: UIButton!
。
在ViewController
课堂上我需要使用这个按钮的 var: firstPercent
。
我怎样才能做到这一点?谢谢你的帮助。
解决方案
在collectionViewDelegate
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
现在声明您的自定义单元实例,然后
您可以CollectionCell.firstPercent
在 ViewController 中使用 addTarget 并设置它或做任何您想做的事情。
推荐阅读
- android - 我的 FFmpeg 在 android 中添加覆盖命令有什么问题
- c++ - 是否可以使用继承在 C++ 中实现 ECS?
- java - 当返回类型是项目的 PaginatedList JAVA 时如何模拟 mapper.query 方法
- java - Azure REST API 使用 java 获取存储 Blob 大小详细信息
- javascript - 创建我自己的 array.prototype.map 方法。如何访问数组?
- android - 使应用程序类单例会导致内存泄漏吗?
- performance - 我们如何提高形式识别器模型的准确性?
- tensorflow - tensorflow.python.framework.errors_impl.InvalidArgumentError:默认 MaxPoolingOp 仅支持设备类型 CPU 上的 NHWC
- mysql - 加入多个表,如果不是一行,则返回零
- cryptocurrency - Libra 验证器连接失败