我在iOS应用中有以下代码:
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self performSelector: @selector(generateDataForDates:) withObject:paramArray afterDelay:0.1];
});
return self.dataArray;
App首先执行return语句,然后执行'performselector',导致数据不一致。 有人有任何线索吗?我需要先执行performselector然后返回语句。
答案 0 :(得分:0)
performSelector:withObject:afterDelay:
将安排选择器在延迟之后执行,并且不会等到执行选择器。它会立即返回。
这会有效,但你为什么要派遣这个街区呢?
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self generateDataForDates:paramArray];
});
return self.dataArray;