How to autoscroll tableview when a new item is added to it?
I tred to use
- (void)scrollToRowAtIndexPath:(NSIndexPath *)indexPath
atScrollPosition:(UITableViewScrollPosition)scrollPosition
animated:(BOOL)animated
But I couldn't figure it out.
Can you please provide sample code?
For better guidance, you should see the docs for [UITableView scrollToRowAtIndexPath:atScrollPosition:animated:]
Below is the instant solution....
int row = [dataController count] - 1;
int section = 0;
NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:row inSection:section];
[[self tableView] scrollToRowAtIndexPath:scrollIndexPath
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];
Add this line to your code from where you wants to scroll tableview.
[myTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[_databaseArray count]-1 inSection:0]
atScrollPosition:UITableViewScrollPositionBottom
animated:YES];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With