繁体   English   中英

单击同一收集单元中的按钮时如何在收集单元中获取标签

[英]How to get the label in the collection cell when click a button in the same collection cell

我有一个带有UICollectionView的视图控制器。 每个UICollectionViewCell都有一个UILabel和一个UIButton 单击相应的UIButton时,如何在UICollectionView打印每个UILabel的文本。

如果我理解正确,则可以UICollectionViewCell子类,将UILabel链接到相应的属性,并创建用于UIButton touch的方法。 这是此方法的示例代码:

@interface MyCustomCollectionViewCell: UICollectionViewCell

@property (weak, nonatomic) IBOutlet UILabel *cellLabel;
- (void)cellButtonClicked:(id)sender;

@end

@implementation
- (void)cellButtonClicked:(id)sender {
    NSLog(@"%@",_cellLabel.text);
}
@end

除此之外,您还可以浏览一些指南,例如指南。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM