首页 > 解决方案 > 在另一个类中使用一个类中的变量

问题描述

我有两个班级:CollectionCellViewController

第一个类用于 Collection View Cell(我在其中放置了一个按钮)。在CollectionCell课堂上,我需要为这个按钮连接插座:@IBOutlet weak var firstPercent: UIButton!

ViewController课堂上我需要使用这个按钮的 var: firstPercent

我怎样才能做到这一点?谢谢你的帮助。

标签: swift

解决方案


collectionViewDelegate

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath

现在声明您的自定义单元实例,然后

您可以CollectionCell.firstPercent在 ViewController 中使用 addTarget 并设置它或做任何您想做的事情。


推荐阅读