2017-07-07 90 views
0

我想禁用我的tableview。意味着没有按钮,TextFields和其他控件可以被触摸,但我也希望我的tableview滚动应该正常工作。启用Tableview滚动但禁用触摸

self.tableView.userInteractionEnabled=true; 

我已经使用了这个,但这使得滚动也禁用。

+0

您的视图只包含一个'tableView'? – kamwysoc

+0

禁用你的单元格的用户交互而不是表格视图 –

回答

1

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

例如,myButton.userInteractionEnabled = NO;

其设置为NO在整个UITableView禁用用于滚动任何手势识别。

0

只需将userInteractionEnabled设置为到您的UITableViewCell即可。

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

要确定停用选择

tableView.allowSelection = false 
+0

这不会阻止对单元格的选择吗? –

+0

@IsaRanjha是的正确thx我更新了我的答案。他没有提及选择,这就是为什么我没有触及 –

0

你必须设置只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 
    } 
0

无需从属性检查器的编码只需取消用户交互Enabled属性的任何一行您的手机

enter image description here或做它通过编码就像

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

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

     return cell 
    } 
0

尝试覆盖的UITableView touchesShouldCancelInContentView方法:

// OC代码:

- (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]; 
} 
0

您可以禁用选择,当你开始滚动。实施UIScrollViewDelegate

scrollViewWillBeginDragging:

​​

scrollViewDidEndDragging:willDecelerate:

tableView.allowsSelection = YES; 
0

选择tableViewCell,并取消用户交互启用的属性
enter image description here

和选择的tableView和CHEC k滚动启用属性
enter image description here
工作正常。

相关问题