Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 750
Marco Buonastella Avatar asked Mar 10 '23 18:03

Marco Buonastella


1 Answers

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
like image 91
Brandon A Avatar answered Mar 20 '23 14:03

Brandon A