1.在我们的一个VC中想要去请求多个请求多个url,那么我们该如何去请求这些数据呀,接下来我来讲下下面使用的方法了呀:
2.使用的是dispatch_group去实现的采用的是异步加载的数据的东西:
#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);
}
还可以不错的可以试一试这个东西了!!!