TabBarController only loads a black screen? - ios

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

Related

Black screen on app launch after latest Xcode 7.2 update

i am making a very complicated app with a lot of classes.
my app worked great and i worked on it for the last month.
the last time i worked on it i added a function and it worked great, i saved the app and ran it a few times since and it worked. the last time i turned my computer on, it prompted me that an update for xcode is available. i updated it, and since then every time i run my app it runs with no errors but on ios simulator it shows a black screen. what can i do? i worked really hard on that app. thanks for the help in advance.
There's few issues that could happened, withou detailed description of this issue, you can try following solutions:
reset simulator
check if your initial controller is set up in storyboard(select controller and press attribute inspector, select is initial view controller):
if you're setting initial view controller programmatically, check if that controller is not nil in app delegate
another tip - try to use UI debugger, that helps a lot:
Any debug messages in the Xcode output? That usually will give a clue.
One thing I can think of, is that in your
- (void) applicationDidFinishLaunching:(UIApplication*)application
delegate, try setting the window's root view controller to your view controller. Example:
[window setRootViewController:viewController];
[window makeKeyAndVisible];
Again, the Xcode debug output will confirm if this is indeed the case though.

What's causing the massive changes in autorotation in 8.1 compared to 8.0.2?

I'm coding a video processing app and was just about to submit it to the app store when ios 8.1 came out. I updated my iPhone as well as XCode and all hell broke loose. In my simple single viewcontroller interface nothing is rotating anymore except for the statusbar, which also doesn't get automatically hidden anymore in landscape mode...
I figured it was because I was using the deprecated willAnimateRotationToInterfaceOrientation: for what little custom rotation actions I had, so I implemented traitCollectionDidChange: and viewWillTransitionToSize: to specs instead. However viewWillTransitionToSize never gets called in my app and traitCollectionDidChange: is only called once, at startup. The device simply isn't telling the app that the device has rotated.
After googling I've also tried using name:UIDeviceOrientationDidChangeNotification. At least my selector does get called for that one but I don't know how to manually handle all rotation.
My didFinishLaunching... and viewDidLoad are very simple. alloc UIWindow, storyboard, set my viewcontroller from there, make it rootviewcontroller, makekeyandvisible. All based on one of Apple's AVFoundation demo apps.
Then in didload I add some subviews and a toolbar etc, nothing out of the ordinary and obviously it did work on 8.0 and 8.0.2 on all kinds of devices as well as the 7.1 simulator etc. Still runs flawlessly on my iPad with 8.0.2... Reason I haven't posted any code is I'm 100% sure everything is correct on that end.
Main weird thing is I can't seem to find anyone with this problem.
No errors in console or elsewhere either.
Does anyone have any idea of what might be causing this? I didn't think a point release would make such massive differences and again, no one else seems to be having this. Could it be an issue/bug in the actual storyboard file?
And, mainly, since I can get rotation notifications through UIDeviceOrientationDidChangeNotification, how do I manually handle all rotation/resizing stuff? I have been looking all over for answers but to no avail and am out of time to spend on this project currently :(
Cheers!
alloc'ing UIWindow will be the problem.
First, Make sure your navigation controller (or whatever you're using) is set as "Initial View Controller" in your storyboard.
Secondly, in your AppDelegate.m file, remove any references to UIWindow and rootViewController that appear in application didFinishLaunchingWithOptions. In my case, removing the following two lines fixed my issues.
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window makeKeyAndVisible];
You also don't need to set the window's rootViewController if using storyboards.
They're simply not needed when using storyboards, but until 8.1 there was never any harm using them. It took my 2 days to figure this out, so hopefully it will help you and others too.

Xcode 5 Simulator Blank White Screen

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"

UIView Rotation Magically Happening

I was given a project that was started by someone else who no longer works here.
I have a UITabBarController which holds some UIViewControllers.
If the application is running on iOS 6, everything runs fine, However as soon as I run it on iOS 5, all UIViews are rotated 90 degrees and given an origin value of something around -100 to -300
I have been able to loop through all view controllers of the tabBar and set
myView.transform = CGAffineTransformMakeRotation(0.0);
myView setFrame:CGRectMake(0,0,1024,748);
The initial view controllers on UITabBarController appear correctly, However, if I ever try to launch a modal view controller, everything is stuffed again. including the modal.
I am running out of ideas on how I could fix this once and for all. I couldn't find anything in the code that rotates the views.
What I could deduce is
on iOS 6, the first subview of the main view holding the UITabBarController is UILayoutContainerView
but on iOS 5 the first subview is of class UIView
If this is an issue with UILayoutContainerView not being supported in iOS5, how can I make the application backwards compatible now?
Note: we only support Landscape (Right/Left) and only on iPad.
Also, I have noticed that if the user rotates the application before initialiazing the UITabBarController and its sub controllers. everything works fine. Even if you re-run the application and not rotate again, still works.
Thanks in advance
If you want your application to stick in landscape mode you the blow code, the issue resides in iOS 5, many people face this issue
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
BOOL returningValue=NO;
if (interfaceOrientation==UIInterfaceOrientationIsPortrait(interfaceOrientation))
{
returningValue=NO;
}
else if(UIInterfaceOrientationIsLandscape(interfaceOrientation))
{
returningValue=YES;
}
return returningValue;
}
Apparently, this is where I went wrong
For iOS 5
when setting the view of the main window of the application, one must use
[self.window addSubview: tabBarController.view];
Instead of (iOS6 only)
[self.window setRootViewController: tabBarController];
I am unsure how that changes everything, and the reason it won't work for iOS 5. Nevertheless, it worked.
Thanks everyone :)

Generating a view programmatically in iOS

Update:
Thanks for all the tips, everyone. The tutorial mentions that a XIB file is provided (which I don't have) so I'm doing something wrong in how I'm creating the the project.
I am following Apple's Core Data Tutorial for iOS. This tutorial has not been updated for ARC—apparently for Xcode 4, since it asks to "create a new project using the Window-Based Application template in the iOS section."
Since that option doesn't exist under Xcode 4.4.1, I looked around Stack Overflow and read that I should create an empty application. As per the tutorial instructions, I created no Storyboard or NIB file.
Other than updating the code for ARC (using strong in place of retain and not implementing the provided dealloc method), I'm confident that the code in my project matches that of the tutorial up to the end of the chapter "The Table View Controller." At this point, the tutorial says I should be able to run the project and get a view.
Instead, I get a blank, black screen.
Maybe my problem is too vague to solve here, but should I perhaps be using a different project template? Which one?
I have only two classes: a RootViewController and an AppDelegate. AppDelegate imports RootViewController and contains a UIWindow property. Again, there is no Storyboard or NIB in the project.
I can provide any code too if there's someplace specific to look.
If you want to check if your setup is correct do the following:
add a background color to your window
self.window.backgroundColor = [UIColor whiteColor];
make sure you tell the window to display itself
[self.window makeKeyAndVisible];
make sure your view controller is the window's rootViewController
self.window.rootViewController = myViewControllerInstance;
Choose Single View Application, and uncheck 'Use storyboards" field. The rest should go the same.

Resources