0

I'm using the below code to scroll to the bottom of my table view when my "send" button is tapped. That said, the animation seems "choppy" even though I've set animated to YES. E.g. When the button is tapped, my entire table view content clears (goes white), and then reappears at the bottom of my tableview (vs. the smooth scrolling animation I'm looking for?)

ViewController.m

- (IBAction)sendReply:(id)sender {

    [self.tableView setContentOffset:CGPointMake(0, CGFLOAT_MAX) animated:YES];

}
  • http://stackoverflow.com/questions/26160484/ios-uitableview-scroll-to-bottom-of-section you can find you answer in the above link – Santhosh Nov 23 '16 at 08:49
  • Possible duplicate of [iOS UITableView Scroll to bottom of section](http://stackoverflow.com/questions/26160484/ios-uitableview-scroll-to-bottom-of-section) – ThunderStruct Mar 18 '17 at 17:12

4 Answers4

2

Call this scrollTableToBottom method in your button action

the condition is used to check any row is there or not. you may ignore that and handle accordingly

- (void)scrollTableToBottom {
    NSInteger rowNumber = [self. tableView numberOfRowsInSection:0];
    if (rowNumber > 0) {
        [self. tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:rowNumber-1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
    }
}

let me know if you have any question.

Happy coding.

Sailendra
  • 1,318
  • 14
  • 29
1

I think you can use default animation of tableview itself

    int lastRowNumber = [tableView numberOfRowsInSection:0] - 1;
    NSIndexPath* ip = [NSIndexPath indexPathForRow:lastRowNumber inSection:0];
    if (ip  > 0) {

    [tableView scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionTop animated:YES];
}
Vinodh
  • 5,262
  • 4
  • 38
  • 68
1

find your Last indexPath and Try this

 [self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:true];

hope this will work

jignesh Vadadoriya
  • 3,244
  • 3
  • 18
  • 29
0

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

check this and let me know

Purushothaman
  • 358
  • 4
  • 22