UIViewController切换的问题

时间:2012-10-26 11:51:50

标签: ios multithreading uiviewcontroller

我的申请有点问题 当我切换视图时,会有一个时间延迟大约3到10秒,此应用程序运行两个排序algorythmen。 (Quick和Bubblesort)在一个额外的线程中。我不知道问题出在哪里。

这里是代码段:

[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];
  });

我认为失败发生在此代码段中。

我希望你能帮助我。

Robybyte

1 个答案:

答案 0 :(得分: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];
     });
});

希望有所帮助。