【发布时间】:2016-03-22 06:42:25
【问题描述】:
我的代码中有 3 个函数。 我为管理队列以执行函数所做的代码。
[self firstMethodWithOnComplete:^{
[self SecongMethodWithOnComplete:^{
dispatch_async(dispatch_get_main_queue(), ^{
[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(CallThirdMethod) userInfo:nil repeats:NO];
});
}];
}];
第一和第二功能
- (void)firstMethodWithOnComplete:(void (^)(void))onComplete {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
//processing here.....
[self CallFirstMethod];
onComplete();
});
}
- (void)SecongMethodWithOnComplete:(void (^)(void))onComplete {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
//processing here.....
[self CallSecondMethod];
onComplete();
});
}
问题是我无法管理他们的执行。我想要这样的执行顺序,即第二个函数仅在第一个结束时执行,第三个在第二次执行结束时执行。 请帮我解决这个问题或提出任何适当的建议。
【问题讨论】:
-
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async(dispatch_get_main_queue(), ^{ NSLog(@"dail image : %@",self.imageUrl); self.imgAppIcon.image = [ UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.imageUrl]]]; }); });
-
你可以这样试试
-
阅读这篇文章:stackoverflow.com/questions/7936570/… 它展示了如何调用一个函数(从网站加载数据),然后在完成后调用第二个函数。它显示了如何将函数作为参数传递。这应该为您指明正确的方向。
标签: ios objective-c function