Ios 删除我拍摄的照片

Ios 删除我拍摄的照片,ios,objective-c,ios7,camera,Ios,Objective C,Ios7,Camera,我正在尝试做一个应用程序,拍摄照片,保存在照片库,选择一个现有的,并删除照片。除了删除的部分,我都做了。你能帮我吗 #pragma mark - Event - (void)TakePhoto { UIImagePickerController * picker = [[UIImagePickerController alloc] init]; picker.delegate = self; picker.sourceType = UIImagePickerCon

我正在尝试做一个应用程序,拍摄照片,保存在照片库,选择一个现有的,并删除照片。除了删除的部分,我都做了。你能帮我吗

#pragma mark - Event

- (void)TakePhoto {

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

    picker.delegate = self;

    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    picker.allowsEditing = YES;

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

    self.newMedia = YES;
}

-(void)ChooseExisting {

    UIImagePickerController * picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.allowsEditing = YES;

    [self presentViewController: picker animated: YES completion:NULL];
    self.newMedia = NO;
}



#pragma mark - UIImagePickerControllerDelaegate

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    NSString *mediaType = info[UIImagePickerControllerMediaType];

    [self dismissViewControllerAnimated:YES completion:NULL];

    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    self.imageView.image = image;

    if(self.newMedia) {
       UIImageWriteToSavedPhotosAlbum(image,self,@selector(image:finishedSavingWithError:contextInfo:),nil);

    }
}

    -(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

        [self dismissViewControllerAnimated:YES completion:nil];
    }

#pragma mark - Action Sheet

    - (void)showActionSheet:(id) sender {
        NSString *actionSheetTitle = @"Action Sheet Demo";
        NSString *destructiveTitle = @"Delete";
        NSString *other1 = @"Take Photo";
        NSString *other2 = @"Chose From Existing";
        NSString *cancelTitle = @"Cancel";

        UIActionSheet *actionSheet = [[UIActionSheet alloc]
                                      initWithTitle:actionSheetTitle
                                      delegate:self
                                      cancelButtonTitle:cancelTitle
                                      destructiveButtonTitle:destructiveTitle
                                      otherButtonTitles:other1, other2, nil];
        [actionSheet showInView:self.view];

    }


    -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
        NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];
        if  ([buttonTitle isEqualToString:@"Delete"]) {
            NSLog(@"Destructive pressed --> Delete Something");
        }
        if ([buttonTitle isEqualToString:@"Take Photo"]) {
            [self TakePhoto];
        }
        if ([buttonTitle isEqualToString:@"Chose From Existing"]) {
            [self ChooseExisting];
        }

        if ([buttonTitle isEqualToString:@"Cancel Button"]) {
            NSLog(@"Cancel pressed --> Cancel ActionSheet");
        }
    }

#pragma mark - Alert

    -(void)image:(UIImage *)image finishedSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
    {
        if (error) {
            UIAlertView *alert = [[UIAlertView alloc]
                                  initWithTitle: @"Save failed"
                                  message: @"Failed to save image"
                                  delegate: nil
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles:nil];
            [alert show];
        }
    }

#pragma mark - Life Cycle

    -(void)viewDidLoad {
        [super viewDidLoad];
        UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        button.frame = CGRectMake(20.0f, 186.0f, 280.0f, 88.0f);
        [button setTitle:@"Show Action Sheet" forState:UIControlStateNormal];
        [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        button.tintColor = [UIColor darkGrayColor];
        [button addTarget:self action:@selector(showActionSheet:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:button];

        if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

            UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                  message:@"Device has no camera"
                                                                 delegate:nil
                                                        cancelButtonTitle:@"OK"
                                                        otherButtonTitles: nil];

            [myAlertView show];

        }



    }



@end

请参阅此关于删除图像的堆栈溢出帖子,但该链接中的信息表明,只有应用程序创建的图像才能删除


你所做的代码部分在哪里?我的意思是你把它包括在问题中。把它包括在问题中并正确地标记它,你会得到帮助。我添加了行动表,使它看起来很好:驻留?有人知道吗??