宽容他人,放过自己。

多张图片删除的实现

Posted on By anchoriteFili

同时上传多张图片图片位置交换图片同时删除多张图片.zip

这个应该是最简单的一个了。。。可是,前面的交换位置没做好,让我死去活来

服务器方面的删除,这里刚开始得到的key值是错的,所以各种错乱,进入封魔状态

@property (nonatomic,retain) NSMutableArray *delImageIDArr; //用于存储所有删除图片的imageID

#pragma mark 删除图片的imageid数组
- (NSMutableArray *)delImageIDArr {
    if (!_delImageIDArr) {
        _delImageIDArr = [NSMutableArray array];
    }
    return _delImageIDArr;
}

#warning 另外页面
-(void)deletPhoto:(NSInteger)index; //代理方法传输删除图片的坐标
#pragma mark 这里是图片的删除,imageView的坐标确定
-(void)ClickProject:(UITapGestureRecognizer *)sender{
    
    if (!isUrlImage[sender.view.tag-1001]){
    if ([_delegate respondsToSelector:@selector(Project:)]) {
        [_delegate Project:sender.view.tag];
    }
    }else{
        NSInteger index = 0;
        if (sender.view == _firstImageView) {
            index = _firstImageView.tag-1000;
        }
        if (sender.view == _secondImageView) {
            index = _secondImageView.tag-1000;
        }
        if (sender.view == _thirthImageView) {
            index = _thirthImageView.tag-1000;
        }
        if (sender.view == _forthImageView) {
            index = _forthImageView.tag-1000;
        }
        if (sender.view== _fifthImageView) {
            index = _fifthImageView.tag-1000;
        }
        if (sender.view == _sixthImageView) {
            index = _sixthImageView.tag-1000;
        }
        
        if (index == 1) {
            return;
        }
        if ([_delegate respondsToSelector:@selector(deletPhoto:)]) {
            [_delegate deletPhoto:index]; //将删除的位置通过代理传输出去
        }
    }
}

#warning 对要删除的imageID数组进行赋值,并将informationDic中的数据进行移除,这个key错,一切免谈了
[self.delImageIDArr addObject:[self.informationDic objectForKey:key]];

#pragma mark-----删除照片
-(void)delPhoto{
    for (NSNumber *imageID in self.delImageIDArr) {
        NSInteger photoId = imageID.integerValue;
        NSString *t = [BaseViewController millisecondsDifferential];
        NSString *jiami = [BaseViewController md5:[NSString stringWithFormat:@"t=%@&UserID=%ld&ImgID=%ld",t,self.userid,photoId]];
        NSString *jiami1 = [BaseViewController Keymd5:jiami];
        NSString *auth = [BaseViewController md5:jiami1];
        
        NSString *strUrl = [NSString stringWithFormat:@"%@%@%@&%@%@&%@%ld&%@%ld",KTHttp,kDelePicture,t,@"auth=",auth,@"UserID=",self.userid,@"ImgID=",photoId];
        [NetManager requestDataWithUrlString:strUrl finished:^(id responseObj) {
            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObj options:NSJSONReadingMutableContainers error:nil];
            NSLog(@"%@",dic);
        } failed:^(NSString *errorMsg) {
            NSLog(@"%@",errorMsg);
        }];
    }
}