Ios UIWindow rootViewController找不到UIViewController子类
我有一个CSRootViewController:UIViewController没有xib文件,一个CSFirstViewController:CSRootViewController有xib文件。对于以下代码,我将得到错误: 应用程序窗口应在以下位置具有根视图控制器: 应用程序启动的结束 使现代化 这是CSFirstViewController的代码。h文件:Ios UIWindow rootViewController找不到UIViewController子类,ios,objective-c,uiviewcontroller,uiwindow,Ios,Objective C,Uiviewcontroller,Uiwindow,我有一个CSRootViewController:UIViewController没有xib文件,一个CSFirstViewController:CSRootViewController有xib文件。对于以下代码,我将得到错误: 应用程序窗口应在以下位置具有根视图控制器: 应用程序启动的结束 使现代化 这是CSFirstViewController的代码。h文件: @interface CSFirstViewController : CSRootViewController @end 和.m
@interface CSFirstViewController : CSRootViewController
@end
和.m文件
@interface CSFirstViewController ()
- (IBAction)pushButtonClicked:(id)sender;
@end
@implementation CSFirstViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - IBAction methods
- (IBAction)pushButtonClicked:(id)sender
{
CSSecondViewController *secondVC = [[CSSecondViewController alloc] init];
[self.rootViewController pushCSViewController:secondVC animated:YES];
}
@end
有人能告诉我原因吗?我找到了解决问题的方法。只需添加[self.windowaddsubview:firstViewController.view];在设置窗口的rootViewController之后。但我仍然不知道为什么会发生这种情况。请将CSFirstViewController.h和.m类放在日志中……您应该记录firstViewController以查看它是否为零。我在这段代码中看不到任何会导致您看到的问题的其他内容。除非您重载了CSFirstViewController init方法,否则您应该使用UIViewController的initWithNibName:bundle:method来使用xib文件初始化根控制器。@V.J.现在添加了您要查看的代码。@rdelmar我已经检查过了,它不是nil。
@interface CSFirstViewController ()
- (IBAction)pushButtonClicked:(id)sender;
@end
@implementation CSFirstViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - IBAction methods
- (IBAction)pushButtonClicked:(id)sender
{
CSSecondViewController *secondVC = [[CSSecondViewController alloc] init];
[self.rootViewController pushCSViewController:secondVC animated:YES];
}
@end