diff --git a/src/UIBubbleTableView.h b/src/UIBubbleTableView.h index e7a617d..e7253f1 100644 --- a/src/UIBubbleTableView.h +++ b/src/UIBubbleTableView.h @@ -27,4 +27,6 @@ typedef enum _NSBubbleTypingType @property (nonatomic) NSBubbleTypingType typingBubble; @property (nonatomic) BOOL showAvatars; +- (BOOL) scrollToBottomWithAnimation:(BOOL)animatedBool; + @end diff --git a/src/UIBubbleTableView.m b/src/UIBubbleTableView.m index 8b91982..eff6916 100644 --- a/src/UIBubbleTableView.m +++ b/src/UIBubbleTableView.m @@ -148,6 +148,24 @@ - (void)reloadData } [super reloadData]; + + [self scrollToBottomWithAnimation:YES]; +} + +- (BOOL) scrollToBottomWithAnimation:(BOOL)animatedBool { + //Autoscroll to bottom of chat when reloadData called. Returns whether scroll actually occurred. + + int sectionCount = [self numberOfSections]; + + if(sectionCount<=0) return NO; + + int rowsInLastSection = [self numberOfRowsInSection:sectionCount-1]; + + NSIndexPath *scrollIndexPath = [NSIndexPath indexPathForRow:rowsInLastSection-1 inSection:sectionCount-1]; + [self scrollToRowAtIndexPath:scrollIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:animatedBool]; + + return YES; + } #pragma mark - UITableViewDelegate implementation