我来这里是正确的需要螺纹的问题,但我似乎不能正确地优化它。正确的线程处理
这里是我的方法:
-(void) method1
{
// -1 to an NSInteger
nsint1--;
[self showActiviyIndicator:YES]; //act as loading screen
[alloc database etc stuffs and retrieving of data here]
//for loop here to check with database, and grey out button depending on database values
for (int i = 1; i<12; i ++)
{
//get values from database and store into variables, then grey out the button if variables are 0.
}
int Val1 = [get from database]
if Val1 = 0
[button setTitleColor:[UIColor Grey]];
someLabel.text = [NSString stringWithFormat:@"%ld", (long)nsint1];
//here's where the problem lies
[self refreshTableSessionList:xx];
[self showActiviyIndicator:NO]
}
内[自refreshTableSessionList:XX],有一个
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)
从服务器数据库获取数据,然后
dispatch_async(dispatch_get_main_queue(),
填充并重新加载tableViewCell。
但是这样会有当我把一个
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)
[alloc database etc stuffs and retrieving of data here]
前变灰的按钮时把dispatch_async(dispatch_get_main_queue(),
冲突,但是这是一个循环中,我不认为这是正确的办法。
什么是克服这种解决办法吗?
使用块从服务器数据库获取数据。 – Kampai
你的循环在哪里? – 2017-03-17 07:37:17
的可能的复制[iPhone - 大中央调度主线程(http://stackoverflow.com/questions/7905192/iphone-grand-central-dispatch-main-thread) – 2017-03-17 07:39:37