今天遇到了iPhone4s和iPhone5上最后一行cell在最下面显示不全的问题。
解决方法:
@property (nonatomic, assign) CGFloat delta;//先定义一个delta保存后面的差值
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
if (self.delta > self.tableView.frame.size.height) {
//如果delta的值大于tableView的高度,就说明整个scrollView的内容还有没有没显示的部分
[self scrollToBottom];
}
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
self.delta =scrollView.contentSize.height - scrollView.contentOffset.y;
}
- (void)scrollToBottom{
if (self.dataSources.count == 0) {
return;
}
//获取最后一行
NSIndexPath *lastIndex = [NSIndexPath indexPathForRow:self.dataSources.count-1 inSection:0];
[self.tableView scrollToRowAtIndexPath:lastIndex atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}