相关疑难解决方法(0)

你可以在GCD/dispatch_async中使用cancel/isCancelled吗?

我一直在想,你能用你用GCD推出的线程取消/ cancelAllOperations/.isCancelled吗?

目前,我只使用布尔值作为标志来取消后台进程.

假设您希望在后台进行大量处理,同时保持UI响应,以便您可以捕获取消按钮(或动画显示处理器工作的动画).这是我们如何做到的......

@interface AstoundingView : UIView
    {
    BOOL    pleaseAbandonYourEfforts;
    blah
    }
@implementation AstoundingView
//
// these are the foreground routines...
// begin, abandon and all-done
//
-(void)userHasClickedToBuildASpaceship
    {
    [YourUIStateMachine buildShip];
    [self procedurallyBuildEnormousSpaceship];
    }
-(void)userHasClickedToAbandonBuildingTheSpaceship
    {
    [YourUIStateMachine inbetween];
    pleaseAbandonYourEfforts = false; // that's it!
    }
-(void)attentionBGIsAllDone
    {
// you get here when the process finishes, whether by completion
// or if we have asked it to cancel itself.
    [self typically setNeedsDisplay, etc];
    [YourUIStateMachine nothinghappening];
    }
//
// these are …
Run Code Online (Sandbox Code Playgroud)

iphone multithreading nsoperation grand-central-dispatch ios

7
推荐指数
1
解决办法
1万
查看次数