tableview双击不更改
时间: 2023-05-22 22:04:06 浏览: 81
您可以尝试在 tableview 的代理方法中,使用 UITapGestureRecognizer 监听双击事件,并在双击事件响应中,修改当前 cell 的属性,从而实现双击更改的功能。以下是可能用到的相关代码:
```objective-c
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"myCell" forIndexPath:indexPath];
cell.textLabel.text = @"Some Text";
// 给 cell 添加 UITapGestureRecognizer 手势
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cellDoubleTapped:)];
tapGesture.numberOfTapsRequired = 2;
[cell addGestureRecognizer:tapGesture];
return cell;
}
- (void)cellDoubleTapped:(UITapGestureRecognizer *)gesture {
// 获取双击的 cell
UITableViewCell *cell = (UITableViewCell *)gesture.view;
// 在这里修改 cell 的属性,比如将 textLabel 的文本改为 "New Text"
cell.textLabel.text = @"New Text";
}
```