iOS-UITableView 滚动到底部和顶部的方法

来源:互联网 发布:node.js和php哪个简单 编辑:程序博客网 时间:2024/05/18 12:03

滚动到底部(分段tableview时,优先选择第二种方法)

1.

- (void)scrollsToBottomAnimated:(BOOL)animated

{

    [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:self.dataArr.count-1inSection:0]  atScrollPosition:UITableViewScrollPositionBottom animated:NO];//这里一定要设置为NO,动画可能会影响到scrollerView,导致增加数据源之后,tableView到处乱跳

}


2.

- (void)scrollViewToBottom:(BOOL)animated

{

    if (self.tableView.contentSize.height > self.tableView.frame.size.height)

    {

        CGPoint offset = CGPointMake(0self.tableView.contentSize.height -self.tableView.frame.size.height);

        [self.tableView setContentOffset:offset animated:animated];

    }

}


//滚动到顶部

[self.tableView setContentOffset:CGPointMake(0,0) animated:NO];



原创粉丝点击