如何用 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
编辑:
我有菲利普建议的窗口(见下文)。但是……我的做法似乎不是最好的。我做对了吗?
UIRootWindow *wnd = [[UIRootWindow alloc] init];
[wnd view];
[self setWindow:wnd.window];