UITableView自动滚动方法


1:

NSUInteger rowCount = [self.tableView numberOfRowsInSection:0];

NSIndexPath* indexPath = [NSIndexPath indexPathForRow:rowCount-1 inSection:0];

[_tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];

 

2:

if (_tableView.contentSize.height < _tableView.height) return;//开始内容的大小没有超过tableView的高时不需要滚动

[UIView animateWithDuration:0.6 animations:^{

_tableView.contentOffset = CGPointMake(0, _tableView.contentSize.height - _tableView.height);

}];

 

获取当前屏幕内的cell

/**

 *  获取显示的最后一条消息的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];

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM