0

让我简要介绍一下我的项目,我正在显示照片库中的图像,我的视图控制器中有 Imageview 和按钮,当我按下按钮时,当我从库中选择照片时,它将导航到照片库图像将在图像视图中显示。

但是当我运行这个项目时,我遇到了运行时错误,请查看代码并建议我解决方案,如果缺少任何文件,请通知我,以便我可以上传您的需要。

我没有得到错误的确切位置,我用谷歌搜索,甚至看到堆栈溢出我仍然找不到任何解决方案

以下是 Viewcontroller.m 文件和控制台查看错误,请告诉我

view controller.m 


//
//  ViewController.m
//  ImagePicker
//
//  Created by Vaibhav on 12/30/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "ViewController.h"

@implementation ViewController

@synthesize imagepic;


-(IBAction)ButtonClicked{



    ipc=  [UIImagePickerController alloc];
    ipc.delegate=self;

    ipc.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentModalViewController:ipc animated:YES ];



}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    imagepic.image= [info objectForKey:UIImagePickerControllerOriginalImage ];
    [ [picker parentViewController] dismissModalViewControllerAnimated:YES ];

    [picker release];


}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [ [picker parentViewController]dismissModalViewControllerAnimated:YES ];
    [picker release];
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end

控制台上的错误消息:

2012-12-30 13:03:05.758 ImagePicker[1409:f803] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0x687b2e0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key image.'
*** First throw call stack:
(0x13b9052 0x154ad0a 0x13b8f11 0x9b0032 0x921f7b 0x921eeb 0x93cd60 0x22f91a 0x13bae1a 0x1324821 0x22e46e 0xd5e2c 0xd63a9 0xd65cb 0x36a73 0x36ce2 0x36ea8 0x3dd9a 0xebe6 0xf8a6 0x1e743 0x1f1f8 0x12aa9 0x12a3fa9 0x138d1c5 0x12f2022 0x12f090a 0x12efdb4 0x12efccb 0xf2a7 0x10a9b 0x1d02 0x1c75)
terminate called throwing an exceptionCurrent language:  auto; currently objective-c
(gdb) 
4

1 回答 1

1

在您的ViewController.xib中,选择您的图像视图并检查IBOutlet Connections. 如果它连接到IBOutlet命名的image,请将其删除。您的图像视图应连接到IBOutlet相应.h文件中的图像视图。您可能已重命名UIImageViewimagePic以前image的 .

于 2012-12-30T08:00:16.787 回答