小编ARe*_*ity的帖子

在后台实现一个块,然后在完成后在主线程上运行另一个块?

如何实现以下块?

我需要在后台运行一些任务.然后在后台任务完成后,一些任务将在主线程中运行.

为什么我使用块是因为我需要更新传递给此方法的视图.

- (void)doALongTask:(UIView *)someView {

    [self doSomethingInBackground:^{

        // Runs some method in background, while foreground does some animation.
        [self doSomeTasksHere];

    } completion:^{

        // After the task in background is completed, then run more tasks.
        [self doSomeOtherTasksHere];

        [someView blahblah];

    }];
} 
Run Code Online (Sandbox Code Playgroud)

或者有更简单的方法来实现这个?谢谢.

cocoa-touch nsthread grand-central-dispatch

2
推荐指数
1
解决办法
3543
查看次数