gpt4 book ai didi

ios - 无法检测按钮 Action Collection View

转载 作者:行者123 更新时间:2023-11-29 10:49:02 26 4
gpt4 key购买 nike

我有一个 Collection View [不是自定义 Collection View ],我想通过单击按钮显示一个警报。但是按钮 Action 没有检测到我的代码的 Action :

    -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{

UICollectionViewCell *cell = [ self.collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];

NSArray *sectionArr=[self.ClassesArr objectAtIndex:indexPath.section];

NSDictionary *data = [sectionArr objectAtIndex:indexPath.row];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(54, 25, 15, 15);
[btn addTarget:self action:@selector(subCateBtnAction:) forControlEvents:UIControlEventTouchUpInside];
[cell addSubview:btn];

}


// the button action
-(IBAction)subCateBtnAction:(UIButton *)btn
{
NSArray *sectionArr=[self.ClassesArr objectAtIndex:sectionindex];

NSDictionary *data = [sectionArr objectAtIndex:btn.tag];
NSString *name = [data objectForKey:@"nombreTarifa"];
UIAlertView *Notpermitted=[[UIAlertView alloc] initWithTitle:@""
message:name
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[Notpermitted show];

}

可能是什么问题谢谢!

最佳答案

看起来您没有将按钮添加到单元格或返回单元格,试试这个:

[cell addSubview:btn];
return cell;

但是您是否意识到 UICollectionView 有一个用于选择的委托(delegate)方法? collectionView:didSelectItemAtIndexPath:

关于ios - 无法检测按钮 Action Collection View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21222253/

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