0

No matter what I do, I cannot get my tableview to scroll to the very bottom when a user gets to my viewcontroller. I'm currently using the following code to try and accomplish this:

ViewController.m

-(void)viewDidAppear {

    if (self.tableView.contentSize.height > self.tableView.frame.size.height)
    {
        CGPoint offset = CGPointMake(0, self.tableView.contentSize.height - self.tableView.frame.size.height);
        [self.tableView setContentOffset:offset animated:YES];
    }
}

I've also tried pasting this in viewDidLoad, as well as viewWillAppear, and no dice whatsoever. And yes, I am using autolayout. Any ideas?

Brittany
  • 1,359
  • 4
  • 24
  • 63
  • What actually happens when you run this code? Does it go into the `if`? Is `offset` a value you would expect? Is the table actually loaded by the time `viewDidAppear` is called? Why not use `UITableView scrollToRowAtIndexPath:atScrollPosition:animated:` once the table is loaded? – rmaddy Sep 08 '18 at 00:34
  • @rmaddy Just realizing the if statement isn't firing...lol that said, if I remove this block of code from the if statement and drop it into viewDidLoad, nothing happens either... How might I go about using scrollToRowAtIndexPath? – Brittany Sep 08 '18 at 01:09
  • `viewDidLoad` is too soon. You need to do the scrolling after the table view actually loads. But you've provided no details so it's difficult to give any more specific advice. – rmaddy Sep 08 '18 at 01:12
  • You'd be right, was executing too soon! Posted how I fixed below. @rmaddy – Brittany Sep 08 '18 at 01:33

0 Answers0