UIActionSheet跳转相册,拍照

时间:2021-05-14 13:30:29

UIImagePickerController *camera;

//点击tableView上得按钮,弹出UIActionSheet

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

    [tableView deselectRowAtIndexPath:indexPath animated:NO];

    

    if (indexPath.section == 0)

    {

        UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消"destructiveButtonTitle:@"相册"otherButtonTitles:@"拍照",nil];

        [actionSheet showInView:self.view];

        actionSheet.destructiveButtonIndex = 0;

    }

    else if (indexPath.section == 1)

    {

        

        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

        

        UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"输入新名字" message:@"" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];

        alertView.alertViewStyle = UIAlertViewStylePlainTextInput;

        

        [alertView show];

        

        

        //得到输入框

        UITextField *tf=[alertView textFieldAtIndex:0];

        tf.placeholder = cell.detailTextLabel.text;

    }

}

//点击UIActionSheet上得按钮,弹出相机,相册

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

{

    [self.view endEditing:YES];

    

    switch (buttonIndex)

    {

        case 1:

            

            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])

            {

                camera.sourceType = UIImagePickerControllerSourceTypeCamera;

            }

            

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

            break;

        case 0:

            

            camera.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

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

            

            break;

        default:

            break;

    }

}