**由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'应用程序试图在目标上显示nil模态视图控制器

时间:2014-10-14 13:45:49

标签: ios objective-c uiimageview uiimagepickercontroller

尝试使相机功能拍照或选择令人兴奋的照片。当我按下" Infoga bild"(选择一张令人兴奋的照片时它会崩溃但是当我拍摄一张新照片时它会起作用。但是图像在图像视图中没有显示。

获取错误**由于未捕获的异常终止应用程序' NSInvalidArgumentException',原因:'应用程序尝试在目标上显示nil模式视图控制器 ***首先抛出调用堆栈:

我从tableview单元格打开控制器视图。

相机功能的代码:

#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

.h代码:

@interface FMEImageview : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate> {
UIImagePickerController *picker;
UIImagePickerController *picker2;
UIImage *image;

IBOutlet UIImageView *ImageView;

}

- (IBAction)Tabild;
- (IBAction)Infogabild;

@end
提前谢谢,我希望我的代码或问题不会太多。我是objective-c

的新手

1 个答案:

答案 0 :(得分:2)

当您在那里创建的控制器名为picker2时,您似乎正在尝试在Infogabild中呈现选择器。