0

当我从我的 secondView 回到我的 mainView 时,我正在我的 secondView 的 viewDidDisappear 方法中处理一些东西。问题是,由于应用程序必须执行的工作,我的 mainView 卡住了。

这是我所做的:

-(void)viewDidDisappear:(BOOL)animated
{
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);

    dispatch_async(queue, ^{

    dbq = [[dbqueries alloc] init];

    [[NSNotificationCenter defaultCenter] postNotificationName:@"abc" object:nil];
    //the notification should start a progressView, but because the whole view gets stuck, I can't see it working, because it stops as soon as the work is done

    dispatch_sync(dispatch_get_main_queue(), ^{

    //work    

    });
});

我究竟做错了什么?提前致谢!

4

1 回答 1

3

您需要在dispatch_async您的queue. 您当前正在// Work主线程中进行工作(假设注释在它所在的位置),此外,您正在阻塞等待此工作的工作线程。

尝试重新安排您的 GCD 调用:

-(void)viewDidDisappear:(BOOL)animated
{
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);

    dbq = [[dbqueries alloc] init];

    [[NSNotificationCenter defaultCenter] postNotificationName:@"abc" object:nil];

    dispatch_async(queue, ^{

        // Perform work here

        dispatch_async(dispatch_get_main_queue(), ^{

           // Update UI here

        });
    });
}
于 2012-07-18T12:42:29.263 回答