I just installed Xcode 5 (or the latest version) and created a new project. I created a storyboard, and added a label, but when I open my application in the iPhone simulator, I simply get a blank white screen with a status bar. What am I doing wrong?
I have OS X 10.9.1 Mavericks.
I know I'm quite late to this, but the solution to this problem is quite simple and is even shown in one of Apple's own tutorials.
Assuming that you started off with an "Empty Project", created a storyboard from scratch, and set your storyboard as the main interface, you need to remove a few lines in the first method of AppDelegate.m.
This:
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;
Should become just this:
return YES;
I'm going to assume that you started an empty project, which doesn't start with a storyboard and then after creating the project, you created a storyboard file.
You have to tell your app which storyboard to load.
In the below screen shot, you'll want to click the "Main Interface" drop down and select the storyboard you want to start your app with.
This is the "Deployment Info" section of the "General" tab of your targets.
You also need to add a couple lines of code to your AppDelegate.m. It should look like this:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"YOUR_STORYBOARD_NAME" bundle:[NSBundle mainBundle]];
UIViewController *vc =[storyboard instantiateInitialViewController];
self.window.rootViewController = vc;
[self.window makeKeyAndVisible];
return YES;
}
Your project does not have a view controller. When you created your project, you should have started with a "Single view project", which would have created a view controller for you. In that case, you would have been able to see your label.
EDIT TO FIX:
If you would like to fix this, remove the property "Main nib file base name." This can be found in the "info" tab of your target.
The problem:
It seems that when you created your application, you selected the "Empty Application" template. Then you added the Storyboard from the user interface section. When you added the label and ran the application, you can't see the "Hello, World" label, because the application does not have a root view controller at the end of the application launch.
Try to create a "Single View Application".
Just wanted to chime in on this thread and shed some light on the matter. I myself was working on my first project and was getting the white screen. I found this article and it helped and it didn't, but this is what worked for me. Everyone is right on what they posted, but I was running 9.2 simulator when in fact I only have 9.1 installed (if you need help with this go to Xcode> Preferences>Downloads and download the appropriate package. Once I did that I ran the simulator and got the white screen. Now my white screen had the carrier and batt icon at the top. To fix this issue in Simulator: Hardware>Device>9.1 and a reboot occurred and then it works...
Hope this helped.
SithAdmin
I had the same issue (blank screen) for a stupid simple error. Actually, the elements appeared and soon fade away.
My mistake was that I was not creating in in Main.storyboard (but LaunchScreen.storyboard in place, so that it obviously disappeared couple of seconds after start).
Stupid but at least, quick to check: create views in Main, not LaunchScreen...
Click "Main.storyboard" -> on right prat "Interface Builder Document" uncheck "Use Auto Layout, "Use Size Classes" & "Use as Lunch Screen"
Related
I'm working with an old Xcode project which is roughly 7/8 years old and I've migrated it to Objective-C 2.0 and to support ARC. The project didn't support Auto-Layout (this was just before it was released) prior to me working on it. I've managed to clear up a lot of the errors/issues i was having with running it in a more modern Xcode IDE (10.2.1). For testing purposes I have implemented this code into the AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height)];
[self.window setBackgroundColor:[UIColor redColor]];
self.window.rootViewController = [UIViewController new];
[self.window makeKeyAndVisible];
return YES;
}
which gives me this for some reason:
This is the result when i run on a iPhone X, iPhone XR or iPhone XS Max, it looks like the top and bottom margins (safe areas) of the screen are not being picked up on. When i debug the view hierarchy they aren't being picked up on either, it just shows the red space? When i throw this code in a new project it works fine and fills up all the space. I'm wondering that because this is a old project there might be a build setting which is restricting the UIWindow from expanding to allow support for new devices?
Also as a side note I've made sure the UIWindow object isn't being manipulated elsewhere.
Try to add "Launch screen interface file base name" (UILaunchStoryboardName) to your Info.plist
It seems that the presence of this key tells the system that you natively support new device types and size classes, so your window can fill all available area.
Don't mess with the storyboard.
Add UILaunchScreen dictionary entry to your .plist.
Include UIColorName string value with background color name defined in the Assets.xcassets.
<key>UILaunchScreen</key>
<dict>
<key>UIColorName</key>
<string>launchScreenBackground</string>
</dict>
In old versions of Xcode, an "Empty Application" would be a project with all the information to build and everything, but no files except the App Delegate would be added.
In the newer versions of Xcode, the "Empty Application" option is no longer the same. Instead of creating a project with no files but the App Delegate, it creates nothing at all! You either have to drag in other files pre-made, or you have to create all the files, including the App Delegate and all of it's once "default" functions.
How would I get the previous version of "Empty Application"? "Single View Application" is a little different, but nothing else seems to be similar.
How would I get the previous version of "Empty Application"
You would have to make it for yourself by paring down the Single View template-based project.
So, for Objective-C:
Delete the storyboard.
Edit the target and delete "Main" where it asks for the storyboard name. Hit Tab to make this change "stick".
Delete the view controller files.
Make a new view controller and (optionally) a .xib paired with it, to give yourself a starting place. Let say it's called MyViewController.
Delete everything in the App Delegate implementation of applicationDidFinishLaunching and replace it with:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = [MyViewController new];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
I'm an Xcode newbie, and I'm trying to make my first training app. Since apparently Empty Application template is the only template that offers pre-integrated Core Data, I choose that. However, after that, I can't get UI to work (it remains empty).
What I did:
Empty Application template
New iPad Storyboard file
Splashed Tab Bar Controller onto it
Changed Main Storyboard in Project's Summary view
Hit ⌘R
Stared at pure-white iPad screen, without any tabs
I tried diffing against another project that I created as a Tab Bar Application (which does reflect my Storyboard changes), without any insight.
Comment out (or remove) the window creation and display code in AppDelegate.m as follows:
- (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;
}
When using a storyboard, a main UIWindow is created for you automatically. What is happening in your case is that you are creating another white window and putting it over the top of the tab UI.
ALSO - note that the Master/Detail template also gives you a core data option.
For an Empty Application project, you have to do two things, after you've added your Storyboard file...
Add a row to your project Info.plist file:
Key: Main storyboard file base name
Value: Storyboard
(or whatever you named your storyboard file)
Delete the contents of application:didFinishLaunchingWithOptions: except return YES;:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
return YES;
}
The Master-Detail and Utility project templates also offer Core Data as an option.
The Apple templates for Core Data are pretty horrible. They stuff far too much functionality into the app delegate and they use lazy loading unnecessarily, which just complicates things even further.
You're better off looking at the generated code and adding the functionality as a separate class in a project you start without Core Data.
To answer your immediate question though, the default empty template creates a window programmatically in the app delegate's application:didFinishLaunchingWithOptions: method. The story board sets a window up itself, so you need to remove that code from the app delegate. The only thing you need in that method is return YES;.
I'm using Xcode 4.0.2 and I opened up one of my projects today to find that a .xib file was missing (the .xib that the MainWindow loads). I can't see it in the Finder and it doesn't appear at all in the Xcode window, yet my application still works as if it's there.
Anyone have any idea what might have happened here?
Cmd+Shift+K to clean. Then rebuild and re-run. What exactly is the issue? That its running with the XIB file or where the XIB file went?.. Maybe its not using a XIB file at all (After-all, its not neccessary).
I'm guessing you didn't have any custom work in that nib. In your delegate on the line self.viewController = [[ViewController alloc] initWithNibName:#"ViewController" bundle:nil]; it tries to load the ViewController.xib file. Since it can't, it's the same as calling self.viewController = [[ViewController alloc] initWithNibName:nil bundle:nil]; which produces a blank generic view.
So I am a beginner developer. And simply just want to have a UITabBarController. I started a new View Based app. The followed the steps by Mark, Nutting and LaMarche from iPhone development for Beginners (chapter 7). I have linked the delegate with my tabBar Controller. I have the code in the delegate method:
[window addSubview:tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
This is in didFinishLauchingWithOptions.
I have released the memory. Thats fine.
I have no idea why its just showing a black screen when i run it. It builds perfectly. no warnings or errors.
any help would be greatly appreciated...
Jack
It has nothing to do with the code - your problem is in your interface builder set up