This question already has answers here:
iOS 9 Xcode 7 - Application appears with black bars on top and bottom
(17 answers)
Closed 6 years ago.
I am working with xCode7 and I am trying to not use storyboards. I have deleted both the launch screen and the main storyboard properties from info.plist and I have created a xib file that is properly linked to the view controllers. In my app delegate I have written the following code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
CGRect screenBounds = [[UIScreen mainScreen] bounds];
UIWindow *window = [[UIWindow alloc] initWithFrame:screenBounds];
ViewController *vc = [[ViewController alloc] init];
[window setRootViewController:vc];
[window makeKeyAndVisible];
[self setWindow:window];
return YES;
}
My xib file looks like this in the editor:
Those buttons are there to show the top and bottom.
In the simulator it looks like this:
Can anyone throw some light into the matter? Thanks, P.
This looks like you should take a look into your Top Bar and Bottom Bar. Make sure is none. I hope this can help you.
[viewController.navigationController setNavigationBarHidden:YES animated:YES];
and
[viewController.navigationController setToolbarHidden:YES animated:YES];
I didn't test it on xcode, maybe there is some errors in my code.
I hope this can help you.
I created a project on xcode 6.0 and I've been running the project on ios8 simulator however when I tried run it on iphone5s ios7.1 simulator the UIWindow frame became to 320x480...
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
above is how I create UIwindow
What shall I do?
You must add correct size iphone/ipad default images, your problem will be solved. , see this link for further details Launch images screen size for iphone
I want to make my iOS application support iPhone 5. So I created a separate xib set for iPhone 5 size. Then I load each xib by checking the screen height.
This is the splash screen loading code inside the AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
UIViewController *viewController1;
if ([UIScreen mainScreen].bounds.size.height==480) {
viewController1 = [[SplashScreen alloc] initWithNibName:#"SplashScreen" bundle:nil];
}
if ([UIScreen mainScreen].bounds.size.height==568) {
viewController1 = [[SplashScreen alloc] initWithNibName:#"SplashScreen5" bundle:nil];
}
self.window.rootViewController = viewController1;
[self.window makeKeyAndVisible];
return YES;
}
But when I change the simulator into Retina 4-inch, my code doesn't get the emulator size. It always executes the 480 if condition.
But other apps I created like this are working properly.
What is the reason for this?
I'm having the exact same problem right now (at the worst moment, of course....).
It did work properly for several weeks, and for a unknown reason, the simulator suddenly considers the 4in simulated device as a 3.5in screen.
cleaning, reset, reboot : same situation...
EDIT : ok, problem solved. T'was because of a missing Default image in the -568#2x format. I knew that was a condition to make the system work, but xcode had apparently decided to get rid off the one I chose. oh well...
I am using a UIStoryboard. I created my application empty, and then I added a storyboard. The storyboard is set as the main storyboard in the project settings and also as the 'Main Storyboard file base name' in the Info.plist.
My app delegate simply returns YES without any other code.
My main.m includes this line of code:
return UIApplicationMain(argc, argv, nil, NSStringFromClass([ARGAppDelegate class]));
I get this message in the console:
Application windows are expected to have a root view controller at the
end of application launch
My view controller is in the UIStoryboard, as the initial view controller.
Just wondering what I am doing wrong here...
My AppDelegate code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
Thats all the code I have, if you are using a storyboard you do not need to create a window right?
Thanks for the help, appreciated!
Update:
I actually changed my AppDelegate code, still does not make a difference:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard_iPhone" bundle:[NSBundle mainBundle]];
UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:#"ARGViewControllerID"];
NSLog(#"%#", initViewController); // Returns a valid ARGViewController object
[self.window setRootViewController:initViewController];
[self.window makeKeyAndVisible];
[self.window makeKeyWindow];
return YES;
}
Application windows are expected to have a root view controller at the end of application launch
sounds like you hadn't embedded in a navigation controller at the beginning of your storyboard
When -applicationDidFinishLaunching:withOptions: does not set up a window or storyboard in code, the next place the system looks is in the info.plist for a default XIB or StoryBoard. The 'Default Storyboard' field in your project info is either empty, or pointing at a non-existent .storyboard file. Click your project in the tree then the 'Summary' tab and fill in the field with the name of your storyboard file.
Unable to find solution after digging through forums and questions and playing with the code, I switched to xibs. Been happy with it since 4 hours ago when I made the transition. I hope I never have to see another error-filled and hard-to-use storyboard file again!
I am getting a message within the console when I run my app that says:
2011-11-16 19:17:41.292 Juice[8674:707] Applications are expected to have a root view controller at the end of application launch
I have heard from others that this has to do with the method didFinishLaunchingWithOptions
If anyone has any suggestions for why I am getting this error, it would be much appreciated.
My code for the method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
return YES;
}
You should replace the
[window addSubview:tabBarController.view];
to
[self.window setRootViewController:tabBarController];
Maybe you built your project with 'Empty Application' and forgot to set the rootViewController in your didFinishLaunchingWithOptions (which exists in your AppDelegate.m).
However, if you build your project with 'Single View Application' or some other type, the project will set the rootViewController via xib by default (which might be a MainWindow.xib in your project).
I had the same problem on iOS 5, after adding a storyboard to an "empty" project. It turns out I had to remove all the lines in AppDelegate.m that set values to self.window.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
//self.window.backgroundColor = [UIColor whiteColor];
//[self.window makeKeyAndVisible];
return YES;
}
If you have MainWindow.xib, make sure you set Main Interface in Target's summary to MainWindow.
The way I got this error Applications are expected to have a root view controller at the end of application launch to disappear, was to ensure the loadView method in my root view controller was calling [super loadView]. Hope this helps someone.
Try using self.window instead of window (if your setup has window being synthesized with something like #synthesize window=_window;):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[self.window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationFade];
return YES;
}
2nd possibility:
In your main.m make sure the last argument is the name of the App Delegate. In your case, it looks like it should be:
retVal = UIApplicationMain(argc, argv, nil, #"JuiceAppDelegate");
Solution:
As #marcus13 said in the comments below.. This was fixed was found in this SO answer: Applications are expected to have a root view controller at the end of application launch - by by moving the UIAlertView methods from -(void)viewDidLoad to -(void)viewDidAppear:(BOOL)animated
Another cause:
I was in IB attaching File Owner to a new small ImageView I'd dragged onto the View. I hadn't called it an IBOutlet in the .h file, so when I ctrl-dragged to it, the new Imageview wasn't listed as a possible connection. The only possibility displayed in the little black box was View. I must have clicked, inadvertently. I made a few changes then ran the program and got the Root Controller error. The fix was reconnecting File Owner to the bottom View in the xib - IB screen.
I just ran into this issue while building a new project from scratch. I added a StoryBoard and build my whole interface, but i did not select a template.
When doing it this way, you have to make sure of 3 main things:
Always select your initial controller (TabBarcontroller or NavigationController) as the initial view in your Storyboard.
Change the code in your Appdelegate.m from this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
to this
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
Check your [ProjectName]-Info.plist file. If there is no key named "Main storyboard file base name", you have to manually add it and set it's value to the name of your storyboard file (without the extension).
After i did all of these steps, my application ran perfectly.
I also had the same problem. All I got was a black screen. Turns out I had inadvertently removed:
[self.window makeKeyAndVisible];
from my code. Hope this helps someone!
I had two outlets assigned to "view" in the storyboard's root view controller. Right-click on "view controller" and make sure there's only one "view".
I also had the same error while developing an app that uses sqlite Database.
I was showing alertView when the db file transfer failed.
This was a mistake since you cannot show any popovers/alertview/actions without any rootViewController set!
I fixed it by ensuring that any function that creates and shows these alerts/popovers/actionsheets are called after
self.window.rootViewController = self.tabBarController;
[self.window makeKeyAndVisible];
[someObject functionthatDisplayAlerts];
I know this post is old but I ran into this today.
It's because I created a UIAlertView in didFinishLaunchingWithOptions.
Assuming then we should not be doing this because I commented it out and the error went away. I removed my comments and the error came back.
The app doesn't crash, I just get that logged error.
I had the same problem with my App. It appeared when I added another view controller to my project and tried to set it as the root view controller in AppDelegate. I tried several solutions, but none of them could fix the problem. Finally I found the cause: I had two localized versions of the MainWindow.xib file (One for german and another for english localization). So I deleted the english file and reconnected the IBOutlets in MainView.xib. This solved the problem.
I'm not sure if this will help anybody else, but if you have used interface builder to create your mainWindow and have done all the linking between the delegate make sure you don't have the following code within application:didFinishLaunching ...
[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]
I was having the same error until I removed the above line. Hope that helps!
EDIT: Doing the above now has my viewControllers viewDidAppear method being called twice ?
If you are using Storyboard, but created an empty project, you probably forgot to set the Main storyboard to your *.storyboard file in the Summary tab in your project settings. It helped me to solve this problem.
If you are starting from an empty you have to make this addition to your AppDelegate.m file, to "point" the window to the rootViewController (self.window.rootViewController = [[[ViewControllerName alloc] initWithNibName:#"ViewControllerName" bundle:nil] autorelease];)
Like so:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
self.window.rootViewController = [[[ViewControllerName alloc] initWithNibName:#"ViewControllerName" bundle:nil] autorelease];
[self.window makeKeyAndVisible];
return YES;
}