2
对不起,我是Cocoa的小菜鸟,因为我是iOS移动开发的新手..直接点,我用Cocoa上的GCD方法将数据分配给tableview,但是当我触发[tableview reloadData]
它不工作。在这里我的示例代码:dispatch_async重新加载UITableView无法正常工作
-(void)updateCell{
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
NSIndexPath* indexPath;
// Insert code to be executed on another thread here
if(clean_data){
for (int i=0; i<clean_data.count; i++) {
indexPath= [NSIndexPath indexPathForRow:i inSection:0];
sqCell *cell = (sqCell *)[stockQ cellForRowAtIndexPath:indexPath];
for (int j=0; j<plist.count; j++) {
NSString *a =[[clean_data objectAtIndex:i]objectAtIndex:1];
NSString *b =[[[plist objectAtIndex:j]objectForKey:@"data"]objectAtIndex:0];
if([a isEqualToString:b]){
cell.last.text =[[clean_data objectAtIndex:i]objectAtIndex:1];
cell.change.text = @"1231231312312";
}
}
}
}
dispatch_async(dispatch_get_main_queue(), ^{
// Insert code to be executed on the main thread here
///reload table here
[self reload];
});
});
}
这里的方法来重新加载数据
-(void)reload{
NSLog(@"reload");
[stockQ setNeedsLayout];
[stockQ setNeedsDisplay];
[stockQ reloadData];
}
控制台显示“刷新”文本,但不点火stockQ UITableCiew ..在我的代码发生什么事?
如果我没有误读OP的代码,他们_are_运行在主线程上的更新,即:'dispatch_get_main_queue()'。它不应该是一个问题,这是异步调用的方法 - 事实上,如果该方法是在主线程上运行,它可能是异步工作(如果代码已经在某些情况下更新表视图) 。 – Monolo
Uhum。你有没有注意到'cell.change.text = @“1231231312312”;'是在异步线程中? – nemesis
哎呀,你是对的! – Monolo