1

我的应用程序有点问题。
当我切换视图时,在这个应用程序运行两个排序算法之后,会有大约 3 到 10 秒的时间延迟。(快速和冒泡排序)在一个额外的线程中。我不知道问题出在哪里。

这里的代码片段:

[alert show];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) {
     time = [Sort sortRuns:(int)slider_durchlaeufe.value WithCapacity:(int)slider_ArraySize.value Reference:alert]; //time is a global reference to my Time object
     [self setDataForStatistik]; // a Method to set the statisik for the next view 
     [alert dismissWithClickedButtonIndex:0 animated:true];
  });

我认为失败出在这段代码片段中。

我希望你能帮助我。

罗比字节

4

1 回答 1

0

您需要在主队列上进行 UI 更新(或任何可能触发 UI 更新的更改)。在查看代码示例时,您会看到很多这种嵌套的“异步到后台队列,然后异步到主队列”。

[alert show];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) {
     time = [Sort sortRuns:(int)slider_durchlaeufe.value WithCapacity:(int)slider_ArraySize.value Reference:alert]; //time is a global reference to my Time object
     dispatch_async(dispatch_get_main_queue(), ^{
         [self setDataForStatistik]; // a Method to set the statisik for the next view 
         [alert dismissWithClickedButtonIndex:0 animated:true];
     });
});

希望有帮助。

于 2012-10-26T13:52:43.850 回答