gpt4 book ai didi

ios - 带有Tap Gesture Recognizer的UILabel无法正常工作

转载 作者:行者123 更新时间:2023-12-01 20:05:20 26 4
gpt4 key购买 nike

我使用UICollectionViewCell设计了一个XIB,在该自定义单元中,我有一个UILabel已启用其用户交互功能。

当我设计viewcontroller时,在我的cell中,这是我的代码。

UITapGestureRecognizer *buyNowTapped = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(buyNowClicked:)];
buyNowTapped.numberOfTapsRequired = 1.0;
cell.buy.tag = indexPath.row;
cell.buy.userInteractionEnabled = YES;
[cell.buy addGestureRecognizer:buyNowTapped];

-(void)buyNowClicked : (id)sender
{
UIButton *button;
UILabel *label;
if([sender isKindOfClass:[UIButton class]])
{
button = (UIButton *)sender;
[self buyService:button.tag];
}
else if ([sender isKindOfClass:[UILabel class]])
{
label = (UILabel *)sender;
[self buyService:label.tag];
}
}

但是添加的轻击手势不起作用。

最佳答案

使用标签属性创建定制单元并使用

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%ld", (long)indexPath.row);
}

注意:在某处添加了TapGestureRecognizer,它防止选择单元格 didselectitematindexpath

关于ios - 带有Tap Gesture Recognizer的UILabel无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39163577/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com