两种方法:
1. 调用scrollToRowAtIndexPath方法
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:self.messageData.count-1 inSection:0];
[self.chatTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];
2. 改变ContentOffset
[self.tableView setContentOffset:CGPointMake(0, self.tableView.contentSize.height -self.tableView.bounds.size.height) animated:YES];
( 注意 )只有在这个方法里面才会执行
-(void)viewDidAppear:(BOOL)animated{
[superviewDidAppear:animated];
}
第一种方法在viewDidLoad和viewWillAppear中不能调用,因为那个时候cell还没生成,会报错,那么在viewDidAppear中调用是可行的,但这样用户点击进去能看到一个下滑的动作,并不好
第二种方法也一样,在viewDidLoad和viewWillAppear中调用没有效果,只有在viewDidAppear中调用,这样也一样有个下滑的动作。想要把动画去掉 把 animated:YES改成NO
网友评论