在viewDidload中,tableview从服务器加载数据
success:^(NSArray *array) {
if (!_dataSource) {
_dataSource = [@[] mutableCopy];
}
if (array) {
[_dataSource addObjectsFromArray:array];
[_tableView reloadData];
}
}
然后每次我从底部拉起,从服务器获取新数据并将其附加到_dataSource(与第一次相同的方式)
success:^(NSArray *array) {
if (!_dataSource) {
_dataSource = [@[] mutableCopy];
}
if (array) {
[_dataSource addObjectsFromArray:array];
[_tableView reloadData];
}
}
现在问题来了:有时从底部拉起,成功获取新数据,但是tableview并没有立即显示新的cell,当我稍微扫一下tableview(甚至只是触摸屏幕)时,新的显示单元格。 可能是什么问题?
编辑
因为每个单元格的高度都不一样,所以我没有重用单元格,每次都初始化一个新的单元格,是这个原因吗?
// TopicCell *cell = [tableView dequeueReusableCellWithIdentifier:TopicCellIdentifier];
// if(!cell){
// cell = [[TopicCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TopicCellIdentifier];
// }
TopicCell *cell = [[TopicCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TopicCellIdentifier];
@Jeffery Thomas,成功就是这样一个AFNetworking block
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:path
parameters:parameters
success:^(AFHTTPRequestOperation *operation1, id responseObject) {
}
failure:^(AFHTTPRequestOperation *operation2, NSError *error) {
}];
最佳答案
作为第一个猜测,我会确保您在主线程(队列)上运行 -reloadData
。这很简单。
success:^(NSArray *array) {
dispatch_async(dispatch_get_main_queue(), ^{
if (!_dataSource) {
_dataSource = [@[] mutableCopy];
}
if (array) {
[_dataSource addObjectsFromArray:array];
[_tableView reloadData];
}
});
}
关于ios - UITableView 在重新加载数据后不会立即显示单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23354354/