各位,我在做上传图片的时候遇到这样的问题,当我选择完图片后。这个时候我想将选中图片中的某个图片进行删除了再添加另外一张图片。我的功能性的东西都做好了,就差这个删除事件不知道该如何去写,我的图片显示是根据图片的路径来进行显示的,我现在就是想要做到的是当我点击这三张图片中的任意一张图片,我都能根据选中图片的路径来删除该张显示的图片,不过仅仅是删除显示中图片,而不是也把手机相册中的图片一并删除了,这里的删除方法中的“sender”已经继承了我传给显示图片的imageNames值,这个是我显示图片的代码:
//选择相片
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
NSData *imageData = UIImagePNGRepresentation(image);
NSString *uuid = [Util generateUuidString];
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
NSString* fullPathToFile = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png",uuid]];
[imageData writeToFile:fullPathToFile atomically:NO];
[dataArray addObject:[NSArray arrayWithObjects:uuid,@"png", nil]];
[PArray addObject:[NSString stringWithFormat:@"%@",fullPathToFile]];
[self Picture:[PArray mutableCopy]];
[picker dismissViewControllerAnimated:NO completion:^{}];
}
//显示照片
-(void)Picture:(NSArray *)arraynamed{
imageNames = arraynamed;
NSInteger number = [imageNames count];
if (number>3) {
[self alertWarn];
}else{
for (int i=0; i<number; i++) {
UIButton *choose = [[UIButton alloc] init];
[choose setBackgroundImage:[UIImage imageWithContentsOfFile:[imageNames objectAtIndex:i]] forState:UIControlStateNormal];
choose.tag = i;
[choose addTarget:self action:@selector(deleteImage) forControlEvents:UIControlEventTouchUpInside];
choose.frame = CGRectMake((i%3)*(60+10)+10, floor(i/3)*(60+24)+80, 60, 60);
[choose setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:choose];
}
}
}
//删除所选相片
-(void)delete:(id)sender{
}