1.在我們的一個VC中想要去請求多個請求多個url,那么我們該如何去請求這些數(shù)據(jù)呀,接下來我來講下下面使用的方法了呀:
2.使用的是dispatch_group去實現(xiàn)的采用的是異步加載的數(shù)據(jù)的東西:
#import"ViewController.h"
@interfaceViewController()
@property(nonatomic,strong)dispatch_group_tmyGroup;
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
self.myGroup=dispatch_group_create();
dispatch_queue_tqueue =dispatch_get_global_queue(0,0);
dispatch_group_enter(self.myGroup);
dispatch_group_enter(self.myGroup);
dispatch_group_enter(self.myGroup);
dispatch_group_async(self.myGroup, queue, ^{
[selffirstRequest];
});
dispatch_group_async(self.myGroup, queue, ^{
[selfsecondRequest];
});
dispatch_group_async(self.myGroup, queue, ^{
[selfthirdRequest];
});
//通話你知完成了
dispatch_group_notify(self.myGroup,dispatch_get_main_queue(), ^{
NSLog(@"4");
});
}
-(void)firstRequest{
NSLog(@"1");
dispatch_group_leave(self.myGroup);
}
-(void)secondRequest{
NSLog(@"2");
dispatch_group_leave(self.myGroup);
}
-(void)thirdRequest{
NSLog(@"3");
dispatch_group_leave(self.myGroup);
}
還可以不錯的可以試一試這個東西了O夹V枇濉!