如何使UITableView停止滚动

时间:2020-11-28 07:18:04

I don't mean that I want to disable scrolling. I want to be able to programmatically tell the table to immediately stop moving (but then it should still be scrollable after than). Is this possible?

我不是说我想禁用滚动。我希望能够以编程方式告诉表立即停止移动(但之后它应该仍然可以滚动)。这可能吗?

4 个解决方案

#1


104  

A UITableView is a subclass of UIScrollView. If you tell it to scroll to its current position, it will stop scrolling so this should work for you:

UITableView是UIScrollView的子类。如果你告诉它滚动到它的当前位置,它将停止滚动所以这应该适合你:

[tableView setContentOffset:tableView.contentOffset animated:NO];

#2


18  

Bind your table view to a variable called tableView, then with the following line you can disable the scrolling:

将表视图绑定到名为tableView的变量,然后使用以下行禁用滚动:

tableView.scrollEnabled = NO;

Set it to YES, if you want it to be scrollable again.

如果您希望它再次滚动,请将其设置为YES。

#3


7  

set tableView.alwaysBounceVertical = NO;

set tableView.alwaysBounceVertical = NO;

#4


-1  

If you are using table view controller,follow below steps

如果您使用的是表视图控制器,请按照以下步骤操作

  1. Select table view controller on storyboard
  2. 在故事板上选择表视图控制器
  3. Go to attribute inspector->scrollview
  4. 转到属性检查器 - > scrollview
  5. Uncheck the scrolling enabled
  6. 取消选中已启用的滚动功能

#1


104  

A UITableView is a subclass of UIScrollView. If you tell it to scroll to its current position, it will stop scrolling so this should work for you:

UITableView是UIScrollView的子类。如果你告诉它滚动到它的当前位置,它将停止滚动所以这应该适合你:

[tableView setContentOffset:tableView.contentOffset animated:NO];

#2


18  

Bind your table view to a variable called tableView, then with the following line you can disable the scrolling:

将表视图绑定到名为tableView的变量,然后使用以下行禁用滚动:

tableView.scrollEnabled = NO;

Set it to YES, if you want it to be scrollable again.

如果您希望它再次滚动,请将其设置为YES。

#3


7  

set tableView.alwaysBounceVertical = NO;

set tableView.alwaysBounceVertical = NO;

#4


-1  

If you are using table view controller,follow below steps

如果您使用的是表视图控制器,请按照以下步骤操作

  1. Select table view controller on storyboard
  2. 在故事板上选择表视图控制器
  3. Go to attribute inspector->scrollview
  4. 转到属性检查器 - > scrollview
  5. Uncheck the scrolling enabled
  6. 取消选中已启用的滚动功能