Ios 启用Tableview滚动,但禁用触摸
我想禁用我的tableview。这意味着不能触摸任何按钮、文本字段和其他控件,但我希望我的tableview滚动条能够正常工作Ios 启用Tableview滚动,但禁用触摸,ios,swift,uitableview,Ios,Swift,Uitableview,我想禁用我的tableview。这意味着不能触摸任何按钮、文本字段和其他控件,但我希望我的tableview滚动条能够正常工作 self.tableView.userInteractionEnabled=true; 我用过这个,但这使得滚动也被禁用。您应该将UITableView单元格中要禁用的元素的单个userInteractionEnabled属性设置为NO,而不是整个UITableView 例如,myButton.userInteractionEnabled=NO 将整个UITableV
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我更新了我的答案。他没有提到选择,这就是我没有选择的原因