【发布时间】:2013-09-16 10:48:57
【问题描述】:
许多长时间运行的异步方法都有完成处理程序块作为输入参数附加到它们
如果操作被取消,我不确定是否应该调用完成处理程序。
-(void)longRunningAsyncOperation:(Input *)input completionHandler:(Block)completionHandler
{
// long running code
// periodic checks for cancelation
if(_canceled)
{
// should completion handler still be called?
return;
}
// more long running code
// completed
completionHandler(someData);
}
【问题讨论】:
-
包含有关作业是否实际完成的信息的完成处理程序怎么样。请参阅 UIView 动画块。有一个变量
BOOL finished,它表示动画是真的完成还是被剪短了。 -
我会推荐
NSOperation处理后台任务和取消 (NSOperation)
标签: ios objective-c coding-style grand-central-dispatch