【发布时间】:2012-04-08 12:16:10
【问题描述】:
如何用 XIB 替换情节提要?
在尝试创建动态视图及其控制器时,我失去了新故事板的所有优势。现在,当试图从项目中删除它时,我创建了一个带有自己的控制器的新 XIB 并在项目设置中替换它:
现在,当尝试运行应用程序时,它会崩溃,并且日志会显示以下内容:
2012-04-08 14:50:16.567 Bazaart[11340:15203] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0x8c15c20> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'
这里是UIRootWindow的代码:
#import <UIKit/UIKit.h>
@interface UIRootWindow : UIViewController
@end
及其对应的实现:
#import "UIRootWindow.h"
@implementation UIRootWindow
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewDidUnload {
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
@end
编辑:
我有 Phillip 建议的窗口(见下文)。但是……我的做法似乎不是最好的。我做得对吗?
UIRootWindow *wnd = [[UIRootWindow alloc] init];
[wnd view];
[self setWindow:wnd.window];
【问题讨论】:
-
附注一下,为了将来的兼容性,您不应以
UI或NS开头自己的类名(想象一下,在SDK 的未来版本中,Apple 引入了一个名为UIRootWindow)。使用你自己的前缀,这样你就会有URKRootWindow这样的东西。
标签: ios xcode interface-builder xcode4.3