[英]How to get the label in the collection cell when click a button in the same collection cell
I have a View Controller with a UICollectionView
. 我有一个带有
UICollectionView
的视图控制器。 Each UICollectionViewCell
has one UILabel
and one UIButton
. 每个
UICollectionViewCell
都有一个UILabel
和一个UIButton
。 How can I print the text of each UILabel
in the UICollectionView
when clicking the corresponding UIButton
. 单击相应的
UIButton
时,如何在UICollectionView
打印每个UILabel
的文本。
If I understood you right, you can subclass your UICollectionViewCell
, link UILabel
to corresponding property and create a method for UIButton
touch. 如果我理解正确,则可以
UICollectionViewCell
子类,将UILabel
链接到相应的属性,并创建用于UIButton
touch的方法。 Here is the sample code of this method: 这是此方法的示例代码:
@interface MyCustomCollectionViewCell: UICollectionViewCell
@property (weak, nonatomic) IBOutlet UILabel *cellLabel;
- (void)cellButtonClicked:(id)sender;
@end
@implementation
- (void)cellButtonClicked:(id)sender {
NSLog(@"%@",_cellLabel.text);
}
@end
Besides it, you can look through some guide, eg this one . 除此之外,您还可以浏览一些指南,例如本指南。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.