gpt4 book ai didi

iOS 滑动检测仅适用于 1 个 UITableViewCell?

转载 作者:行者123 更新时间:2023-12-01 19:04:53 25 4
gpt4 key购买 nike

我正在尝试在 2 个表格单元格上添加滑动检测。但是,到目前为止,滑动检测仅适用于一个表格单元格。

以下是我的部分代码:

- (void)viewDidLoad {

[super viewDidLoad];
numbers = [[NSMutableArray alloc]init];
tableCellTrash = [[NSMutableArray alloc]init];

mSwipeRecognizer= [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(removeCell:)];
[mSwipeRecognizer setDirection:( UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight)];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"CustomPlaceCell";
CustomPlaceCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomPlaceCell" owner:nil options:nil] objectAtIndex:0];
[numbers addObject:cell];
[cell addGestureRecognizer:mSwipeRecognizer];
NSLog(@"Cell");
}

return cell;
}

-(void)removeCell:(UISwipeGestureRecognizer *)aSwipeGestureRecognizer{
NSLog(@"Swipe Detected!");
}

任何人都知道为什么滑动检测仅适用于其中一个单元格?

最佳答案

一个 UIGestureRecognizer只能与单个 View 关联。您应该为每个单元格设置不同的手势识别器。您可以将 GestureRecognizer 创建移动到

     if (cell == nil) {
cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomPlaceCell" owner:nil options:nil] objectAtIndex:0];
[numbers addObject:cell];

UISwipeGestureRecognizer *swipeRecognizer= [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(removeCell:)];
[swipeRecognizer setDirection:( UISwipeGestureRecognizerDirectionLeft | UISwipeGestureRecognizerDirectionRight)];

[cell addGestureRecognizer:swipeRecognizer];

NSLog(@"Cell");
}

关于iOS 滑动检测仅适用于 1 个 UITableViewCell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20323662/

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