GCD实现一张一张的传输图片,即传完一张再传另外一张

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath

{

    if (collectionView == self.hotelOrderReviewView.tripTypeCollectionView)

    {

        

        //        [arr_typeofTripUnPressImage replaceObjectAtIndex:indexPath.row withObject:[arr_typeofTripPressImage objectAtIndex:indexPath.row]];

        

        CTTypeOfTripCollectionViewCell * cell = (CTTypeOfTripCollectionViewCell*)[collectionView cellForItemAtIndexPath:indexPath];

        [cell configTypeOfTrip:[arr_typeofTripPressImage objectAtIndex:indexPath.row]];

//        cell.accessibilityIdentifier = [arr_typeofTripPressImage objectAtIndex:indexPath.row];

        

        for (int i = 0; i <= 6; i++) {

            if (indexPath.row != i) {

                

                CTTypeOfTripCollectionViewCell * cell = (CTTypeOfTripCollectionViewCell*)[collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];


                

                [cell configTypeOfTrip:[arr_typeofTripUnPressImage objectAtIndex:i]];


            }


        }

        

    }

    else if (collectionView == self.hotelOrderReviewView.userImageCollectionView)

    {

        [arr_selectedImage removeAllObjects];

        

        

        CTHotelOrderUploadImageCell * cell = (CTHotelOrderUploadImageCell*)[collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];


        


        

        SGImagePickerController *picker = [[SGImagePickerController alloc] init];

        picker.maxCount = 6;

        [picker setDidFinishSelectImages:^(NSArray *images) {

            [arr_selectedImage addObjectsFromArray:images];

            [arr_selectedImage addObject:[UIImage imageNamed:@"emailus_photo"]];

            [self updateContentSize];

            [collectionView reloadData];

            

            dispatch_group_t group = dispatch_group_create();

            semaphore = dispatch_semaphore_create(1);

            dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);


            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

                for (int i = 0; i < arr_selectedImage.count;i++) {

                    


                    dispatch_group_async(group, queue, ^{

                        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);


                        dispatch_async(dispatch_get_main_queue(), ^{

                            

                            

                            CTHotelOrderUploadImageCell * cell1 = (CTHotelOrderUploadImageCell*)[collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:i inSection:0]];

                            

                            HUD = [[MBProgressHUD alloc] initWithView:cell1];

                            [cell1 addSubview:HUD];

                            

                            //如果设置此属性则当前的view置于后台

                            HUD.dimBackground = YES;

                            

                            //设置对话框文字

                            //            HUD.labelText = @"请稍等";

                            

                            //显示对话框

                            [HUD showAnimated:YES whileExecutingBlock:^{

                                //对话框显示时需要执行的操作

                                [self upLoadImageToServerWithImage:[arr_selectedImage objectAtIndex:i] andHotelID:_order.hotelId];

                                

                            } completionBlock:^{

                                //操作执行完后取消对话框

                                [HUD removeFromSuperview];

                                HUD = nil;

                            }];

                            

                            

                            

                            

                        });

//                        dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);



                    });


                    

                    

                    

                }

            });

            

            


            

            

            

            

            

            

        }];

        [self presentViewController:picker animated:YES completion:nil];

        

    }

    

}




-(void)upLoadImageToServerWithImage:(UIImage* )image andHotelID:(long)hotelID

{

    

    CTReqHotelCommentUpLoadImage *_request = [CTReqHotelCommentUpLoadImage reqeustEntity];

    _request.fileBytes = UIImageJPEGRepresentation(image,0.1).base64EncodeToString;

    _request.hotelID = hotelID;

    

    

    

    

    

    [[CTModelAPIStoreManager sharedStoreManagerpostRequest:_request success:^(CTRespHotelCommentUpLoadImage *object) {

        if (CT_CHECK_CLASS(object, CTRespHotelCommentUpLoadImage)) {

            _result = object;

            [self onSuccessful];

            dispatch_semaphore_signal(semaphore);


        }else{

            [self onFailed];

            [[CTModelAPIStoreManager sharedStoreManager] clearCache:[_request requestHashCode]];

        }

//        [self setTitleView];

        

    } failure:^(NSError *error) {

//        [self setTitleView];

        [self onFailed];

    } cache:YES];

    

    

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值