简体   繁体   中英

UITableView not scrolling to the bottom

I have a UITableView (on a UIViewController) on which I want to ad an iAd banner on the top, but below a toolBar I already have on the top. I'm trying to shift the the tableView (in reference to the view) so I can locate the banner in the space left blank.

To check it ou, I create an action in which I shift the tableView frame:

  -(IBAction)iAdAction:(id)sender{

   self.tableViewConc.frame=CGRectMake(0, 94, 320, 367);}

where 94 is the summ of 44 from the toolbar and the 50 from the banner.

The action works correctly but then, I cannot scroll to the bottom of the tableView, when I try it, it bounces back. I've tried to change the height of the tableView in the same action ( 430 instead of 367, for instance) but it doesn't work. I've also tried it on IB, but it doesn't work either.

I feel that I'm missing something but I cannot remember what.

Any help?

Thanks in advance!

Not being able to scroll to the bottom of the tableview is usually a symptom of its height being too large. (ie it's cut off at the bottom)

Don't compute the height you need and put those numbers in your code. Just find out what it should be from the view hierarchy. For example, you might compute the height of your table view with CGRectGetHeight(self.view.bounds) - CGRectGetMaxY(self.iAdView) , and the view's y origin with CGRectGetMaxY(self.iAdView) assuming that the iAd view and your table view are both subviews of self.view . Or, even better, just use autoresize masks or autolayout to keep the table view the right size.

你可以试试

self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 44, 0);

I just had this embarrassing scenario where my UITableView would "bounce" but it wouldn't scroll to the bottom. For ME, the problem was that I was dynamically setting the row heights, and my very last cell was getting calculated with a cell height of -115 (yes, negative). Once I fixed that to return a positive number, my scrolling worked just fine.

Even we can achieve the same in storyboard.

Select tableView --> from the storyboard control click on 'add Missing constraints'. That will add the constraint to tableView and View.

That helped me to resolve this issue. Screenshot_Link

Check the number of the row that you can't see.

After in your viewDidLoad, add this method:

myTableView.contentInset = UIEdgeInsets(top: 0,left: 0,bottom: yourCellHeight * rowHeight,right: 0)

I hope I have been helpful

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM