Tableview scrolling bounces back and hides the bottom cells
Asked Answered
L

3

7

I have a view that is shown under a navigation controller. The view contains one subview at the top portion and a table view at the bottom. The table might have rows that extend beyond the visible height based on data. When I have rows that are below the last visible row, if I scroll the view up, it bounces back, it does not stay there. Is there a way to make it stay? I tried making the parent view a scroll view and that did not help. My view is from a XIB.

Lugworm answered 2/10, 2009 at 5:26 Comment(0)
T
27

Sounds like the size of your UITableView is slightly larger than the area available on the iPhone screen. This might be because the view didn't take into account the size of hte navigation bar. As a test, go into Interface Builder and make the UITableView much smaller, say half the size, so you can clearly see the top and bottom. See if you still have the same bouncing.

If the sizes are correct, UITableView does not need a UIScrollView to function as expected. In fact, there would be few reasons, that I can think of right now (other than horizontal scroll ones), that you'd want a UITableView inside a UIScrollView.

Thirtieth answered 2/10, 2009 at 6:23 Comment(3)
Thanks for your observation, that fixed the problem.Lugworm
Great. I see from your history that you are not selecting any of the accepted answers as the official answers to your questions. Maybe you did not know this, but to the left of the answers you see a check mark. If you click that you then are selecting the answer that was the solution to your problem. That gives me some reputation, plus for people who have the same question, they see which answer helped you out. When you get a chance, please click the check mark. thanks.Thirtieth
Awesome, tried a ton of things before this fixed my problem.Conrad
G
0

In your top level View Controller, in the "Simulated Metrics"-settings, set Top Bar and/or Bottom Bar (depending on what's displayed in your View Controller) to "opaque". Then resize the Table View to fit beween the Navigation Bar and the Tool Bar/Tab Bar. Finally, add two constraints:

  1. Top Space to Top Layout Guide
  2. Bottom Space to Bottom Layout Guide

Worked very well for me, regardless of orientation.

Gunny answered 20/8, 2014 at 13:6 Comment(0)
C
0

If you are not using Storyboard, you could try the following (swift) code:

tableView.contentInset = UIEdgeInsetsMake( (self.navigationController!.navigationBar.frame.origin.y + self.navigationController!.navigationBar.frame.size.height), 0, 0, 0)

self.view.addSubview(tableView)

If you have a toolbar or (if you are using a TabBarController), you'll need to adjust the bottom too:

tableView.contentInset = UIEdgeInsetsMake( (self.navigationController!.navigationBar.frame.origin.y + self.navigationController!.navigationBar.frame.size.height), 0, 0, 0)

self.view.addSubview(tableView)

Please note that this is a simple and 'rough' code. You can make it prettier if needed :)

Commandment answered 16/6, 2016 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.