我正在Xcode 5中构建我的第一个IOS 7 iPad应用程序 - 但我需要一些帮助解决此问题。NSException与UIImagePickerController
我下面this教程:
我不太明白什么是作家意味着: “所以打通testPickerViewController.h,我们希望在下面的类添加引用。”
UINavigationControllerDelegate, UIImagePickerControllerDelegate>
我来到这里我的观点或者Controller.h文件:
#import "ViewController.h"
@interface DetailViewController : ViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>
{
UIImagePickerController *imgPicker;
IBOutlet UIImageView *customImage;
}
@property(nonatomic, retain)UIImagePickerController *imgPicker;
@end
我看来Controller.m或者文件:
#import "DetailViewController.h"
@interface DetailViewController()
@end
@implementation DetailViewController
@synthesize imgPicker, customImage;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
// Init the image picker
self.imgPicker = [[UIImagePickerController alloc]init];
self.imgPicker.allowsEditing = YES;
self.imgPicker.delegate = self;
self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
- (IBAction)AddImage:(id)sender {
// Let the user add an image for the specific subject
[self presentModalViewController:self.imgPicker animated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editingInfo {
customImage.image = img;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}
@end
我跑的应用程序没有做什么,我在上面写,导致main.m文件中出现NSException。
我在这里做错了什么?
编辑
main.m
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
int main(int argc, char * argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
编辑
2014年5月17日14:56:47.509对myApp [1424:60B] *终止应用程序由于未捕获的异常 'NSUnknownKeyException',原因:'[setValue:forUndefinedKey:]:此类不是关键图像的关键字编码兼容值。'
而异常消息是...? –
以NSException类型的未捕获异常终止 – Erik
在这种情况下,您是否放置了断点并检查哪一行导致异常? –