1.滾動到最后一行
- (void)scrollToBottom
{
? ? if ([UIDevice isIphone6] || [UIDevice isIphone6p]) {
? ? ? ? if (self.fpmModel.responseData.count > 0) {
? ? ? ? ? ? [self.messageTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:self.fpmModel.responseData.count - 1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
? ? ? ? }
? ? }else{
? ? ? ? if (self.messageTableView.contentSize.height > self.messageTableView.bounds.size.height) {
? ? ? ? ? ? [self.messageTableView setContentOffset:CGPointMake(0, self.messageTableView.contentSize.height -self.messageTableView.bounds.size.height) animated:NO];
? ? ? ? }
? ? }
}
iPhone5及其以下
2.解決跳屏問題(明顯的刷新)
對于iPhone5以下設(shè)備,由于CPU處理速度較慢兰吟,感覺不到跳屏問題褂痰,但在iPhone6以上設(shè)備梦皮,CPU處理速度很快揭蜒,為了避免明顯的跳屏缺猛,要延遲100毫秒等待數(shù)據(jù)刷新完畢再滾動夜畴。
注意:該地方的延遲處理是延遲滾動介衔,當(dāng)數(shù)據(jù)源很多的時候宏粤,滾動瞬間就能滾動到最后一行脚翘,但要展示最后一行的數(shù)據(jù),在Cell比較復(fù)雜的時候可能會稍微慢绍哎,所以會出現(xiàn)跳屏問題来农,而在慢設(shè)備上滾動的處理較慢,故感覺不到跳屏崇堰。
[self.messageTableView reloadData];
? ? ? ? ? ? // 延遲100毫秒等待數(shù)據(jù)刷新完畢
? ? ? ? ? ? dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1*NSEC_PER_SEC));
? ? ? ? ? ? dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
? ? ? ? ? ? ? ? [self scrollToBottom];
? ? ? ? ? ? });