调试器显示此信息:
2013-07-16 15:23:15.731 app2[2501:c07] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x71a4140> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key imageview.'
我的应用目前由两个视图控制器组成。
- “ViewController”只有一个按钮来启动应用程序并按下按钮启动新视图。
ViewController.h #import <UIKit/UIKit.h> @interface ViewController : UIViewController - (IBAction)startBtn:(id)sender; @end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)startBtn:(id)sender {
UIViewController *flipViewController = [[UIViewController alloc] initWithNibName:@"AppViewController" bundle:[NSBundle mainBundle]];
[self presentViewController:flipViewController animated:YES completion:NULL];
}
@end
我的第二个视图控制器“AppViewController”有一个 UIImageView 和一个 UIButton。它的代码是:
AppViewController.h
#import <UIKit/UIKit.h>
@interface AppViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIImageView *imageview;
@end
和
AppViewController.m
#import "AppViewController.h"
@interface AppViewController ()
@end
@implementation AppViewController
- (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 from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
我面临的问题是,当我通过 Ctrl 将图像视图拖动到“h”文件中连接“xib”文件和“h”文件之间的属性时,我的应用程序在模拟器中崩溃并给了我错误。
我认为这对你们中的许多人来说可能是一个太简单的错误,但是,我无法纠正它。我已经阅读了这个论坛上的许多帖子并且尝试过最多,包括@synthesize 修复等。