1:get
NSUInteger rowCount = [self.tableView numberOfRowsInSection:0];animation
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:rowCount-1 inSection:0];it
[_tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];io
2:table
if (_tableView.contentSize.height < _tableView.height) return;//開始內容的大小沒有超過tableView的高時不須要滾動ast
[UIView animateWithDuration:0.6 animations:^{scroll
_tableView.contentOffset = CGPointMake(0, _tableView.contentSize.height - _tableView.height);im
}];sort
獲取當前屏幕內的celltab
/**
* 獲取顯示的最後一條消息的indexPath
*
* @return indexPath
*/
- (NSIndexPath *)getLastIndexPathForVisibleItems
{
NSArray *visiblePaths = [self.audienceHead indexPathsForVisibleItems];
if (visiblePaths.count == 0) {
return nil;
}else if(visiblePaths.count == 1) {
return (NSIndexPath *)[visiblePaths firstObject];
}
NSArray *sortedIndexPaths = [visiblePaths sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
NSIndexPath *path1 = (NSIndexPath *)obj1;
NSIndexPath *path2 = (NSIndexPath *)obj2;
return [path1 compare:path2];
}];
return (NSIndexPath *)[sortedIndexPaths lastObject];
}