Reputation: 55
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];
}
Upvotes: 0
Views: 690
Reputation: 358
- (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
Upvotes: 0
Reputation: 1497
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.
Upvotes: 2
Reputation: 3310
find your Last indexPath and Try this
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:true];
hope this will work
Upvotes: 1
Reputation: 5268
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];
}
Upvotes: 1