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