gpt4 book ai didi

ios - 延迟 UITableViewCell 触摸响应

转载 作者:行者123 更新时间:2023-11-29 11:01:46 24 4
gpt4 key购买 nike

我正在尝试实现一个“SETTINGS 页面”,例如左侧为表格 View 、右侧为 ImageView 的 Split View。一切都很好,但如果尝试更快地点击它, TableView 单元格触摸会有延迟。 DidSelectRowAtIndex 路径未被调用,但单元格闪烁。

我试过的,

  1. 图像更改逻辑从DidSelectRowAtIndex

    移到willSelectRowAtIndexPath
  2. 从委托(delegate)方法中删除了所有内容(以检查是否由于加载 图片)

如何解决这个有线问题?

表格数据源

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"tutorialCell";
CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TutorialTableCell" owner:nil options:nil];
cell = [nib objectAtIndex:0];
}
NSDictionary * dic = [dictArray objectAtIndex:indexPath.row];
cell.tutorialText.text = [dic valueForKey:TUTORIAL_TEXT];
cell.tutorialImage.image = [UIImage imageNamed:[dic valueForKey:TUTORIAL_ICON]];
cell.contentView.backgroundColor = [UIColor colorWithHex:@"#36393D" alpha:1.0];
UIView *bgColorView = [[UIView alloc] init];
[bgColorView setBackgroundColor:[UIColor colorWithHex:@"#1f1f1f" alpha:1.0]];
[cell setSelectedBackgroundView:bgColorView];
return cell;
}

TableView 委托(delegate)

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSDictionary * dic = [dictArray objectAtIndex:indexPath.row];
_tutorialImageView.image = [UIImage imageNamed:[dic valueForKey:TUTORIAL_IMAGE]];
}

最佳答案

UITableViews 是 UIScrollViews 的子类,默认启用 delaysContentTouches。这是因为 UIScrollView 在允许触摸进入其 subview 之前会尝试确定触摸是滑动手势还是滚动 Action 的一部分。如果您真的想禁用该操作,您可以将 TableView 的 delaysContentTouches 设置为 NO。这可能会使滚动行为有点奇怪,因为点击将立即转到您的 TableView 的单元格。您可能会发现,与非延迟触摸操作相比,您实际上更喜欢延迟触摸操作。

编辑 Clement 说他已经尝试过了,所以这是另一个想法。

在发布的代码中,您至少在最初从磁盘 (imageNamed:) 加载这些图像。 UIKit 可能会做一些缓存。如果您的教程图像非常大,您可能无法更快地加载它们,所以请提前加载它们。您可以加载所有图像并使用相同的 [dic valueForKey:TUTORIAL_IMAGE] 键将它们放入字典中。然后在 tableView:didSelectRowAtIndexPath: 中,您可以将 _tutorialImageView.image 设置为字典中的(已加载的)图像之一。

关于ios - 延迟 UITableViewCell 触摸响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15608796/

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