我以前在苹果的网站上看到过这个例子,但由于某种原因,我找不到它,这是在胡思乱想。我创建了一个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:07:41
@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;
}如果这是您真正使用的代码,则将以下代码添加到您的界面中:
UIWindow *window;看看有没有帮助。
发布于 2011-05-24 13:37:48
对于你的窗口,你需要设置你的rootViewController。顺便说一句,你的名字"rootController“有点误导,b/c UIWindow有一个属性rootViewController。因此,要让它工作而不是行[self.window addSubview:rootController.view];,您应该执行下面的self.window.rootViewController = self.rootController;
如果您想将您的代码与工作代码进行比较,只需从模板创建新项目即可。选择基于视图的应用程序,它具有您要查找的架构。
发布于 2011-05-24 13:48:46
打开TestViewController.xib并检查那里是否连接了任何错误的插座。选择FilesOwner并转到连接检查器。错误的出口将会显示为褪色..在这种情况下,它将被标记为
https://stackoverflow.com/questions/6106004
复制相似问题