4
我只是想換我周圍的大中央調度(GCD)的頭,我似乎無法找到這個更新UI元素被添加到一個視圖之前
答案所以我知道,一般你不應該從主線程以外的任何線程更新UIView元素。所以這是非法的:
dispatch_async(workerQueue, ^{
self.view.backgroundColor = [UIColor redColor];
});
但是你是否允許在視圖元素被實際添加到視圖之前工作?換句話說,這是允許的嗎?
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];
}
});