Application windows are expected to have a root view controller at the end of application launch - even with all known issues fixed
Solution 1
I ran into exactly the same thing trying to add a UITableView to a single-view app. Instead, create a default Master-Detail Application project (file->new->target->...) and see the AppDelegate's implementation of didFinishLaunchingWithOptions:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
MDMasterViewController *masterViewController = [[MDMasterViewController alloc] initWithNibName:@"MDMasterViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
Rather than directly setting your view controller as the window's rootViewController, you need to create a navigation controller init'ed with your view controller for initWithRootViewController, then set that nav controller as the window's rootViewController. (Notice you also have to squirrel away that nav controller in a property so it doesn't get destructed).
Solution 2
Just change this:
[window addSubview:tabBarController.view];
to this:
[window setRootViewController:tabBarController];
Or whatever was in the addSubView:
Solution 3
Try to define the default view controller in your project menu,
select your project => Summary => Main Interface => Type your main view controller
every time that i started new project i faced the same error as you,doing this every time solved,hope this help you.
Thomas Clayson
Updated on October 09, 2020Comments
-
Thomas Clayson over 3 years
I have this problem, however none of the information I can find on this forum or the internet in general seems to be able to help me.
There seem to be two places where this error can come about:
- main.m - my function looks like this:
int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } }
The last argument in
UIApplicationMain
returns anNSString
value of the class of myAppDelegate
. This is therefore working fine.2.AppDelegate.m - there is an "older" way of setting the root view controller which is like this:
[self.window addSubview:rootViewController];
However, in my app it has already been updated to:
self.window.rootViewController = self.viewController; [self.window makeKeyAndVisible];
So none of the current information on the internet works. It is slightly more puzzling as my colleague can get it to work on his computer perfectly fine - he was the one that sent me the app source code so all the settings and code should be exactly the same.
I am trying to launch this in the simulator. It is built against iOS 5, but I'm trying to run it on the iOS 6.0 simulator.
I have the latest XCode (4.5.1).
Is there any reason this would be happening? And how can I rectify it?
Many thanks
Tom
-
Thomas Clayson over 11 yearsThis isn't really an answer. I can't set break points because the error occurs as soon as
application:didFinishLaunchingWithOptions
returnsYES/NO
so there isn't a specific place that the app crashes. Its not a crash either, I can't backtrace in GDB. The app seems to be running, but nothing appears on the screen in the simulator. -
Rui Peres over 11 yearsI just throw my 2 cents. Sorry if I couldn't help you.
-
Benjamin Netter over 10 yearsNow it's Project > General > Deployment Info > Main Interface
-
Keith Adler about 10 yearsThis was the fix for me.