【发布时间】:2016-07-26 03:51:38
【问题描述】:
我有一个表格视图。它将从服务器接收混乱的数据。每次 tableview 收到数据时,我都希望它在底部显示最新的数据。我打电话给scrollToRowAtIndexPath:atScrollPosition:animated:,但它落后于我的应用程序,当滚动到 tableview 底部时,我无法在屏幕上做任何其他事情。
这是我的主要代码
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *identifier = @"tableViewCell";
DLtestCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}
NSDictionary* dict = arr[indexPath.row];
cell.myLabel.attributedText = dict[@"content"];
[cell.myImageview sd_setImageWithURL:dict[@"imageUrl"] placeholderImage:[UIImage imageNamed:@"transparentPlaceHolder"]];
return cell;
}
这里是滚动到底部的主要代码
- (void)reloadTableView
{
dispatch_async(dispatch_get_main_queue(), ^{
NSIndexPath *lastRow = [NSIndexPath indexPathForRow:row inSection:0];
[self.tableView insertRowsAtIndexPaths:@[lastRow] withRowAnimation:UITableViewRowAnimationLeft];
});
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
}
【问题讨论】:
-
尝试在主线程(performOnMainThread)方法中重新加载
标签: ios objective-c uitableview tableview reloaddata