Advertisement
MikeAtPureChat

-scrollToBottomOfMessagesAnimated:

Jul 9th, 2015
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void)scrollToBottomOfMessagesAnimated:(BOOL)animated {
  2.     if (self.room.messages.count > 0 && [self.manager count] == 0) {
  3.         [self updateManagerForChats];
  4.     }
  5.     NSInteger x = [self.messagesTableView numberOfRowsInSection:0] - 1;
  6.     NSInteger y = [self.manager count]; // Doing this because the operations are at the end always
  7.    
  8.     if (x <= 0 || y <= 0) {
  9.         [self.messagesTableView setContentOffset:CGPointMake(0, CGFLOAT_MAX)];
  10.     } else {
  11.    
  12.         NSInteger rowNumbers = [self.messagesTableView numberOfRowsInSection:0]-1;
  13.        
  14.         dispatch_after(0, dispatch_get_main_queue(), ^{
  15.             [self.messagesTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[self.messagesTableView numberOfRowsInSection:0]-1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
  16.         });
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement