簡體   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