UITableView scrolls back because it's content size is equal to it's frame (or near to it). If you want to scroll it without returning you need add more cells: table view content size will be large then it's frame.
You can add a UITableView to a UIScrollView and have it scroll horizontally.
To scroll to the top of our tableview we need to create a new IndexPath . This index path has two arguments, row and section . All we want to do is scroll to the top of the table view, therefore we pass 0 for the row argument and 0 for the section argument. UITableView has the scrollToRow method built in.
Since a scrollView has a panGesture we can check the velocity of that gesture. If the tableView was programmatically scrolled the velocity in both x and y directions is 0.0. By checking this velocity we can determine if the user scrolled the tableView because the panGesture has a velocity.
I think you want to set
tableView.alwaysBounceVertical = NO;
In Swift:
tableView.alwaysBounceVertical = false
You can verify the number of visible cells using this function:
- (NSArray *)visibleCells
This method will return an array with the cells that are visible, so you can count the number of objects in this array and compare with the number of objects in your table.. if it's equal.. you can disable the scrolling using:
tableView.scrollEnabled = NO;
As @Ginny mentioned.. we would can have problems with partially visible cells, so this solution works better in this case:
tableView.scrollEnabled = (tableView.contentSize.height <= CGRectGetHeight(tableView.frame));
In case you are using autoLayout this solution do the job:
tableView.alwaysBounceVertical = NO.
So there's are multiple answers and requires a all content at once place so I'm adding this answer:
If you're using AutoLayout, by setting this only should work for you:
tableView.alwaysBounceVertical = false
Just find this option and untick
"Bounce Vertically
" option.
Here's the reference:
If you're not using AutoLayout:
override func viewDidLayoutSubviews() {
// Enable scrolling based on content height
tableView.isScrollEnabled = tableView.contentSize.height > tableView.frame.size.height
}
try this
[yourTableView setBounces:NO];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With