我用图像和按钮制作了自定义集合视图单元格。如何通过单击它来创建此按钮的方法我需要知道单击单元格的确切内容。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
[self.myCollectionView registerNib:[UINib nibWithNibName:@"myGirlCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:@"CELL1"];
myGirlCollectionViewCell *cellGirl = [collectionView dequeueReusableCellWithReuseIdentifier:@"CELL1" forIndexPath:indexPath];
cellGirl.girlImg.image = [[_mainArray objectAtIndex:indexPath.row]objectForKey:@"img"];
NSString *name = [[_mainArray objectAtIndex:indexPath.row]objectForKey:@"name"];//the name I want to see in the method!
[cellGirl.btnName addTarget:self action:@selector(clickMe:) forControlEvents:UIControlEventTouchUpInside];
return cellGirl;
}
-(void)clickMe:(UIButton *)button{
//here *name
}
我应该如何提供此参数?
答案 0 :(得分:2)
为按钮设置标记。
cellGirl.btnName.tag = indexPath.row;
然后在这个方法里面。
-(void)clickMe:(UIButton *)button{
//here *name
//check for tag value like this
if (button.tag == 0)
{
// Your code here
}
}