2014-05-17 6 views
-2

저는 Xcode 5에서 첫 IOS 7 iPad 앱을 제작하고 있습니다.하지만이 문제에 대한 도움이 필요합니다. 나는 꽤 작가와 함께 무엇을 의미하는지 이해하지UIImagePickerController를 사용한 NSException

:

나는 this 튜토리얼 다음과 같은거야. "그래서 testPickerViewController.h을 열고 우리가 클래스 참조에 다음에 추가 할" 을

UINavigationControllerDelegate, UIImagePickerControllerDelegate> 

여기 내보기 controller.h 파일을 가지고 :

내보기 controller.m 파일
#import "ViewController.h" 

@interface DetailViewController : ViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate> 
{ 
UIImagePickerController *imgPicker; 
IBOutlet UIImageView *customImage; 
} 

@property(nonatomic, retain)UIImagePickerController *imgPicker; 

@end 

: 나는 정상에 쓴하지 않고 응용 프로그램을 실행

#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 [1,424 : 60B] 앱 종단 * 의한 캐치되지 않는 예외 'NSUnknownKeyException'로, 이유 : '[setValue : forUndefinedKey :] :이 클래스는 키 이미지에 대해 키 값을 코딩하지 않습니다.'

+1

예외 메시지는 ...입니까? –

+0

NSException – Erik

+0

의 catch되지 않은 예외로 종료하면 중단 점을 넣었으며이 경우 예외를 발생시키는 행을 확인 했습니까? –

답변

0

인터페이스 작성기 (IB)에서 IBOutlet customImage에 대한 연결을 확인하고 참조하는 콘센트 이름과 UIImageView가 일치하는지 확인하십시오. IB의 Connection Inspector (원 안의 작은 화살표)를 클릭하여 확인할 수 있습니다.

링크를 게시 한 자습서에서 IBOutlet UIImageViewimage으로 표시됩니다. IBOutlet의 이름을 변경하고 다시 연결하는 것을 잊었다 고 가정합니다. 또한 속성 선언 옆의 점이 채워지거나 비어 있는지 확인하여 IBOutlet customImage이 연결되어 있는지 확인할 수 있습니다. 채워진 = 연결됨 및 비어 있음 = 연결되지 않음. 함께 IBOutlet 대한 속성 선언

예 :

@property (weak, nonatomic) IBOutlet UIImageView * customImage; 

또한 <UINavigationControllerDelegate, UIImagePickerControllerDelegate> 프로토콜이다. "UIViewControllerUINavigationControllerDelegate 및 을 따르기를 원합니다. 특정 이벤트가 발생하면 직접 코드를 구현하고 싶습니다."라고 간단히 말하면 @interface 선언에 해당 행을 추가하면됩니다.

+0

링크를 확인했는데 정확합니다. 내 .h 코드를 약간 바 꾸었습니다. 내 업데이트를 참조하십시오. – Erik

+1

ImageView에서 이미지 링크를 제거했는데 갑자기 성공했습니다. – Erik

+0

환상적입니다. 나는 모든 것이 지금 당신을 위해 일해 주어 다행입니다. 계속해서 튜토리얼을 읽으면 많은 것들을 얻을 수 있습니다. – Jonathan