简体   繁体   English

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

[英]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.

相关问题 如何通过单击更改集合视图单元格中的标签颜色 - how to change the label colour in collection view cell by click 从集合视图中的可重用单元格中获取按钮单击(XIB文件) - Get button click from reusable cell in collection view (xib file) 如何在表格视图单元格中单击按钮时获取标签值 - How to get label value in table view cell on button click in cell 如何使用CoreData从选定的集合视图单元格中获取标签文本? - How to Get Label Text from Selected Collection View Cell with CoreData? 如何在集合视图中对单元格单击创建按钮操作 - How to create button action on cell click in a collection view 具有相同XIB单元格和按钮的多个集合视图 - Multiple Collection Views with same XIB Cell and button 单击集合视图上的单元格,如何在详细视图上获得相同的图像? - How to get the same image on detailed view on clicking a cell on collection view? 如何在表视图单元格中的按钮单击上获取标签以进行prepareForSegue - How to get label on button click in tableview cell for prepareForSegue 在swift 4.0中点击收集视图单元格时更改标签的文本 - Changing the text of a label when a collection view cell is tapped in swift 4.0 迅速-滚动集合视图时,标签移动到单元格的左上方 - Swift - Label moves to the upper left of the cell when scrolling the collection view
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM