Autoscroll only if the log view is in the last line
giummy opened this issue · comments
I have modify the method logMessage:
- (void)logMessage:(DDLogMessage *)logMessage
{
dispatch_async(dispatch_get_main_queue(), ^{
[_messages addObject:logMessage];
BOOL scroll = NO;
if(_tableView.contentOffset.y + _tableView.bounds.size.height >= _tableView.contentSize.height)
scroll = YES;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_messages.count-1 inSection:0];
[_tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationBottom];
if(scroll) {
[_tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}
});
}
Thanks @giummy!