bkb*_*abs 5 iphone multithreading objective-c grand-central-dispatch ios
我只是想绕着Grand Central Dispatch(GCD),我似乎无法找到答案
所以我知道通常你不应该从主线程以外的任何线程更新UIView元素.所以这是非法的:
dispatch_async(workerQueue, ^{
self.view.backgroundColor = [UIColor redColor];
});
Run Code Online (Sandbox Code Playgroud)
但是,在将视图元素实际添加到视图之前,您是否可以处理它们?换句话说,这是允许的吗?
dispatch_async(workerQueue, ^{
UIButton *thisLevelButton = [UIButton buttonWithType:UIButtonTypeCustom];
thisLevelButton.frame = CGRectMake(x, y, BUTTON_WIDTH, BUTTON_HEIGHT);
thisLevelButton.tag = kLevelButtonTags + j;
int levelState = [[[thisCat objectForKey:[levelNamesInCat objectAtIndex:j]] objectAtIndex:4] intValue];
[thisLevelButton setBackgroundImage:[UIImage imageNamed:@"ccLSButton50lock"]forState:UIControlStateNormal];
thisLevelButton.alpha = 0.5;
[thisLevelButton addTarget:self action:@selector(unlockButtonAction:) forControlEvents:UIControlEventTouchUpInside];
dispatch_async(dispatch_get_main_queue(), ^{
[self.view addSubview:thisLevelButton];
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1599 次 |
| 最近记录: |