48

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?

Lorenzo B
  • 33,216
  • 24
  • 116
  • 190
MusiGenesis
  • 74,184
  • 40
  • 190
  • 334
  • 2
    Try looking at this link: http://stackoverflow.com/questions/986392/programmatically-force-a-uiscrollview-to-stop-scrolling-for-sharing-a-table-vie This could also work: [tableView setContentOffset:tableView.contentOffset animated:NO]; Hope it helps. :) – waylonion Apr 17 '12 at 20:11
  • This title is sort of misleading. – Jonathan King Oct 02 '14 at 19:56
  • 1
    @JonathanKing: I don't think it is at all. There's a big difference between "how do I make a table stop scrolling" and "how do I prevent a table from scrolling". It's also why questions have a title and a longer description to go with it. – MusiGenesis Oct 03 '14 at 20:05
  • @MusiGenesis Good point, although I would say a title such as "How do I make a UITableView stop moving during scroll animation" or even use just replacing 'scrolling' with 'moving' (which you have written in your description) would be more accurate. – Jonathan King Oct 03 '14 at 21:57

4 Answers4

118

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:

[tableView setContentOffset:tableView.contentOffset animated:NO];
ndfred
  • 3,842
  • 2
  • 23
  • 14
  • Well, that sort of worked, but it only works to stop the table from scrolling. If the table doesn't have enough rows to actually scroll, if I pull down it will still bounce a little bit, which triggers the scrollViewDidScroll: call, which I'm trying to prevent from happening by stopping the scrolling – MusiGenesis Apr 17 '12 at 21:02
  • 5
    In that case you should disable scrolling if the table view does not have enough rows. – ndfred Apr 17 '12 at 21:46
  • 1
    Note that you MUST use the method indicated in this answer, setting the `contentOffset` property directly will not cancel any scrolling animations that are in progress. – Beltalowda Dec 15 '17 at 18:16
23

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

tableView.scrollEnabled = NO;

Swift version:

tableView.isScrollEnabled = false

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

Display Name
  • 4,502
  • 2
  • 47
  • 63
8

set tableView.alwaysBounceVertical = false;

logeshpalani31
  • 1,416
  • 12
  • 33
Himanshu padia
  • 7,428
  • 1
  • 47
  • 45
  • How does this answer anything to do with the question? – Rambatino Jun 02 '14 at 23:44
  • 2
    @Rambatino: I think the user was responding to my comment under the selected answer about also preventing the bouncing, although this would have been better as a comment. – MusiGenesis Feb 25 '15 at 15:21
1

If you are using table view controller,follow below steps

  1. Select table view controller on storyboard
  2. Go to attribute inspector->scrollview
  3. Uncheck the scrolling enabled
VJVJ
  • 435
  • 3
  • 21