我有一个没有xib文件的CSRootViewController:UIViewController
,一个带有xib文件的CSFirstViewController:CSRootViewController
。对于波纹管代码,我会收到错误:
“应用程序窗口应该有一个根视图控制器 应用程序启动结束“
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
CSFirstViewController *firstViewController = [[CSFirstViewController alloc] init];
self.window.rootViewController = firstViewController;
[self.window makeKeyAndVisible];
return YES;
}
以下是CSFirstViewController
'代码。 .h文件:
@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
任何人都可以指出原因吗?
答案 0 :(得分:0)
我找到了解决问题的方法。只需在设置窗口[self.window addSubview:firstViewController.view];
后添加rootViewController
即可。但我仍然不知道为什么会这样。