I have a CSRootViewController:UIViewController
without xib file, a CSFirstViewController:CSRootViewController
with xib file. For bellow code I will get the error:
"Application windows are expected to have a root view controller at the end of application launch"
- (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;
}
Here is the CSFirstViewController
'code. .h file:
@interface CSFirstViewController : CSRootViewController
@end
And the .m file
@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
Any guys could point me out the reason?
I find the way to handle my question. Just add [self.window addSubview:firstViewController.view];
after set window's rootViewController
. But I still don't know why this happens.