我正在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
在這種情況下,您是否放置了斷點並檢查哪一行導致異常? –