我有一个可能来自任何线程的回调.当我得到这个回调,然后我想在主线程上执行某个任务.
我是否需要检查我是否已经在主线程上 - 或者是否因为没有执行此检查而遭受任何惩罚?请调用下面的代码?
dispatch_async(dispatch_get_main_queue(), ^{
// do work here
});
Run Code Online (Sandbox Code Playgroud) 我在UITableViewCell上放了一个UIProgressView,就像这样:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"downloadcell"];
if(cell==nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:@"downloadcell"] autorelease];
UIProgressView* downPreView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
downPreView.tag = 123;
downPreView.frame = CGRectMake(400,70, 200,10);
[cell.contentView addSubview:downPreView];
}
Run Code Online (Sandbox Code Playgroud)
当下载大小发生变化时,我这样做:
UIProgressView* downPreView = (UIProgressView*)[cell viewWithTag:123];
downPreView.progress = downloadPre;
Run Code Online (Sandbox Code Playgroud)
但是,只有在我触摸单元格或其他单元格之后,downPreView的外观才会立即改变,那么如何在UITableViewCell上立即更改UIProgressView?