我有以下代码让用户拍照或从相册中选择。虽然从相机拍摄照片效果很好,但当我选择触发动作的按钮时,专辑会出现,但实际上您无法选择照片。当我从相机方法启动拍摄时,启动从相册方法中选择时,我确实在控制台中收到警告。以下是相关代码和警告。
.h
@interface sitespecTakePhoto : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@property (strong, nonatomic) NSString *pbvlocname;
@property (strong, nonatomic) IBOutlet UITextField *descTextField;
@property (strong, nonatomic) IBOutlet UIImageView *imageField;
@property (strong, nonatomic) UIImagePickerController *imagePicker;
@property (nonatomic, strong) IBOutlet UILabel *successLabel;
@property UIImage *imageToSend;
@property NSString *desc;
- (IBAction)imageFromCamera:(id)sender;
- (IBAction)resignKeyboard:(id)sender;
-(IBAction)uploadButtonClicked:(id)sender;
@end
.m
- (IBAction)imageFromCamera:(id)sender
{
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
[self presentViewController:imagePicker animated:YES completion:nil];
}
- (IBAction)imageFromAlbum:(id)sender
{
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentViewController:imagePicker animated:YES completion:nil];
}
#pragma mark - Image Picker Delegate Methods
// Dismiss the image picker on selection and use the resulting image in our ImageView
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage: (UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
[[imagePicker presentingViewController] dismissViewControllerAnimated:YES completion:nil];
[imageField setImage:image];
imageToSend = image;
}
// On cancel, only dismiss the picker controller
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[[imagePicker presentingViewController] dismissViewControllerAnimated:YES completion:nil];
}
- (IBAction)resignKeyboard:(id)sender
{
desc = descTextField.text;
[sender resignFirstResponder];
}
以及按下按钮以触发imageFromAlbum方法时出现的警告:
Warning: Attempt to present <UIImagePickerController: 0x1d59d6b0> on <UINavigationController: 0x1e0319f0> while a presentation is in progress!
再一次,专辑显示但是当您点击图像或按下取消按钮时没有任何反应,我觉得这个方法几乎不识别UIImagePicker委托方法而imageFromCamera方法是。提前谢谢任何帮助!
答案 0 :(得分:0)
错误消息中的关键短语是“在演示文稿正在进行中”。这表明你在另一个presentViewController
被解雇时正在这样做。我敢打赌,你不小心将这个按钮挂钩到两个方法,以便它试图同时执行两个presentViewController
命令。使用Interface Builder右侧的连接检查器将其理顺。