UITableView+NIMScrollToBottom.m 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //
  2. // UITableView+NTESScrollToBottom.m
  3. // NIMDemo
  4. //
  5. // Created by chris.
  6. // Copyright (c) 2015年 Netease. All rights reserved.
  7. //
  8. #import "UITableView+NIMScrollToBottom.h"
  9. @implementation UITableView (NIMKit)
  10. - (void)nim_scrollToBottom:(BOOL)animation
  11. {
  12. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  13. NSInteger row = [self numberOfRowsInSection:0] - 1;
  14. if (row > 0)
  15. {
  16. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:row inSection:0];
  17. [self scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];
  18. // if (animation) {
  19. // [UIView animateWithDuration:0.25f animations:^{
  20. //
  21. // } completion:^(BOOL finished) {
  22. // if (self.contentSize.height > self.mj_h) {
  23. // self.contentOffset = CGPointMake(0, self.contentSize.height - self.mj_h);
  24. // }
  25. // }];
  26. // }else{
  27. if (self.contentSize.height > self.mj_h) {
  28. self.contentOffset = CGPointMake(0, self.contentSize.height - self.mj_h);
  29. }
  30. // }
  31. }
  32. });
  33. }
  34. @end