UITableView滑动到最下面

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
-(void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
if (self.chatArray.count>0)
{
NSInteger rows = [self.chatTab numberOfRowsInSection:self.chatArray.count-1];
if(rows>0)
{
NSIndexPath *ip = [NSIndexPath indexPathForRow:rows-1 inSection:self.chatArray.count-1];
[self.chatTab scrollToRowAtIndexPath:ip atScrollPosition:UITableViewScrollPositionBottom animated:NO];
}
}

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

if (self.chatTab.contentSize.height > self.chatTab.frame.size.height)
{
CGPoint offset = CGPointMake(0, self.chatTab.contentSize.height - self.chatTab.frame.size.height);
[self.chatTab setContentOffset:offset animated:NO];
}

});
}