Marco Buonastella
Marco Buonastella

Reputation: 57

UITableView does not scroll to bottom (Swift IOS)

My UITableView does not scroll to the bottom and stops before all the content can be displayed (cuts off the last few rows). I have checked that my UITableView is equal to the screen size, but the content size is greater than screen and table height. I am not sure why this is happening.

Upvotes: 4

Views: 9991

Answers (5)

Rohit Nikam
Rohit Nikam

Reputation: 59

Unchecking "Under Bottom Bars" of respective ViewController from storyboard inside attribute inspector solved my issue.

Upvotes: 0

Nupur Sharma
Nupur Sharma

Reputation: 1214

In my case...removing

tableview.frame.size = tableview.contentsize worked

Upvotes: 0

Brandon A
Brandon A

Reputation: 8289

1) Do you have a UITabBar at the bottom of your screen? This content may be covered by the bar. IF so, go your storyboard and to your UIViewController you have the UITableView placed in and uncheck it's Under Bottom Bars boolean.

enter image description here

2) You might have an NSLayoutConstraint set at the bottom that is to the negative. Meaning your UITableView will be extending to the bottom of the screen. IF so, reset your UITableView's bottom constraint to 0.0.

enter image description here

3) You might want to try using UITableView scroll method. Get the index of the last cell:

[yourTableView scrollToRowAtIndexPath:lastCellIndex 
                 atScrollPosition:UITableViewScrollPositionTop 
                         animated:YES];

4) UITableView is subclassed from UIScrollView. Therefore you can treat it as such.

If ever cell in the UITableView has the same height, you can multiple the number of objects in your datasource times the height of the cell, then you know what value to enter into your UIScrollView/TableView method as contentOffset:

(void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated

Upvotes: 4

Hussain Shabbir
Hussain Shabbir

Reputation: 15035

May be you need to set the automatic dimensions:-

You can pinned your tableView to the superview with the correct constraint and if you are using the custom tableview cell then pinned all the labels constraint (leading, trailing, top and bottom)to the cell and then inside your ViewController viewDidLoad method write the below code:-

tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 44.0

Once your constraints are correct then your table view cell content size will resize dynamically depends on the content.

Note:-

Do not use the tableview delegate method(heightForRowAtIndexPath) to adjust the height if you are using UITableViewAutomaticDimension

Upvotes: 2

hasan
hasan

Reputation: 24195

That most probably happen in small iPhone devices. because you didnt set your bottom constraint of the tableview correctly. Check that constraint. if it doesnt exist add it.

Upvotes: 2

Related Questions