Ios 启用Tableview滚动,但禁用触摸

Ios 启用Tableview滚动,但禁用触摸,ios,swift,uitableview,Ios,Swift,Uitableview,我想禁用我的tableview。这意味着不能触摸任何按钮、文本字段和其他控件,但我希望我的tableview滚动条能够正常工作 self.tableView.userInteractionEnabled=true; 我用过这个,但这使得滚动也被禁用。您应该将UITableView单元格中要禁用的元素的单个userInteractionEnabled属性设置为NO,而不是整个UITableView 例如,myButton.userInteractionEnabled=NO 将整个UITableV

我想禁用我的tableview。这意味着不能触摸任何按钮、文本字段和其他控件,但我希望我的tableview滚动条能够正常工作

self.tableView.userInteractionEnabled=true;

我用过这个,但这使得滚动也被禁用。

您应该将
UITableView
单元格中要禁用的元素的单个
userInteractionEnabled
属性设置为
NO
,而不是整个
UITableView

例如,
myButton.userInteractionEnabled=NO


将整个
UITableView
设置为
NO
将禁用用于滚动的任何手势识别器。

只需将
userInteractionEnabled
设置为false,即可将
UITableView单元格设置为
false

func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell {
  // do your stuffs
  cell.userInteractionEnabled = false
  return cell
}
取消选定

tableView.allowSelection = false

您只需设置
isUserInteractionEnabled
&
selectionStyle

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)

        cell.selectionStyle = .none;
        cell.isUserInteractionEnabled = false;

        return cell
    }

尝试覆盖UITableView
触摸ShouldCancelIncontentView
方法:

//代码:

- (BOOL)touchesShouldCancelInContentView:(UIView *)view
{
    //when you want to scroll and touch event don't deliver to controls. 
    if ([view isKindOfClass:[UIControl class])){
          return YES;
    }

    return [super touchesShouldCancelInContentView:view];
}

您可以在开始滚动时禁用选择。实施
UIScrollViewDelegate

ScrollViewWillBeginDraging:

tableView.allowsSelection = NO;
ScrollViewDiEndDraging中:将减速:

tableView.allowsSelection = YES;

选择tableViewCell并取消选中“已启用用户交互”属性

然后选择tableView并检查已启用滚动的属性


它工作正常。

您的视图只包含一个
表视图
?禁用单元格的用户交互,而不是表视图。这不会阻止单元格的选择吗?@IsaRanjha是的,没错,thx我更新了我的答案。他没有提到选择,这就是我没有选择的原因