[英]** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target
Trying to make a camera function to take a photo or choose an exciting photo. 尝试使相机具有拍摄照片或选择令人兴奋的照片的功能。 When I press "Infoga bild"(choose a exciting photo it crashes but when I take a new photo it works. But the image doesn't show in the image view. 当我按“ Infoga bild”(选择一张令人兴奋的照片时,它会崩溃,但是当我拍摄新照片时,它会起作用。但是,该图像不会在图像视图中显示。
Getting the error ** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target *** First throw call stack: 收到错误**由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'应用程序试图在目标上显示nil模态视图控制器***首先抛出调用栈:
I open the controller view from a tableview cell. 我从一个tableview单元打开控制器视图。
the code for the camera function: 相机功能的代码:
#import "FMEImageview.h"
@implementation FMEImageview
- (IBAction)Tabild {
picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
[picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[self presentViewController:picker animated:YES completion:nil];
}
- (IBAction)Infogabild{
picker2 = [[UIImagePickerController alloc] init];
picker2.delegate = self;
[picker2 setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[self presentViewController:picker animated:YES completion:nil];
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary*)info{
image = [info objectForKey:UIImagePickerControllerOriginalImage];
[ImageView setImage: image];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[self dismissViewControllerAnimated:YES completion:nil];
}
-(void) viewDidLoad {
[super viewDidLoad];
}
-(void) didReceiveMemoryWarning{
[super didReceiveMemoryWarning];
}
@end
The .h code: .h代码:
@interface FMEImageview : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate> {
UIImagePickerController *picker;
UIImagePickerController *picker2;
UIImage *image;
IBOutlet UIImageView *ImageView;
}
- (IBAction)Tabild;
- (IBAction)Infogabild;
@end
Thx in advance and i hope my code or question doesn't suck to much. 事先谢谢,我希望我的代码或问题不会太多。 I'm new to objective-c 我是Objective-C的新手
当您在其中创建的控制器名为picker2时,您似乎正在尝试在Infogabild中呈现Picker。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.