tableView 显示时自动滑动到最后一条

来源:互联网 发布:c语言贪吃蛇源代码 编辑:程序博客网 时间:2024/06/14 22:24

首先写一个属性,用于控制是否已经在最后一条

@property (nonatomic, assign) BOOL isScrollBottom;// 初始化self.isScrollBottom = NO;//判断,利用代理方法来实现-(void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{//    if([indexPath row] == ((NSIndexPath*)[[tableView indexPathsForVisibleRows] lastObject]).row){//    }        if (self.isScrollBottom == NO) {            [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:self.newsData.count-1 inSection:0] atScrollPosition:UITableViewScrollPositionNone animated:NO];            if (indexPath.row == self.newsData.count-1) {                self.isScrollBottom = YES;            }        }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

这样的话在tableview出现的时候就会自动滑动到最后一条

原创粉丝点击