我以前在苹果的网站上看到过这个例子,但由于某种原因,我找不到它,这是在胡思乱想。我创建了一个TestViewController.h和.m文件,该文件是UIViewController的子类,并且有一个.xib。在TestAppDelegate.h中,我有:
@interface TestAppDelegate : NSObject <UIApplicationDelegate> {
TestViewController *rootController;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet TestViewController *rootController;在TestAppDelegate.m中,我有:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
[self.window addSubview:rootController.view];
[self.window makeKeyAndVisible];
return YES;
}然后在我的MainWindow.xib中,我拖动一个ViewController,将类更改为TestViewController,控制将outlet从TestAppDelegate拖动到TestViewController。它构建得很好,但是当我运行它时,我得到:
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<TestViewController 0x4d06570> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key label.'我不记得我在这些步骤中遗漏了什么。任何帮助都将不胜感激。谢谢。
发布于 2011-05-24 14:20:17
在Interface Builder中检查您的插座,您有一个名为"label“的东西并不存在。删除对此的引用,您就可以开始工作了。
https://stackoverflow.com/questions/6106004
复制相似问题