I have been trying to run my Xcode project on my iOS simulator an iPhone but I only get a black screen. I have tried multiple solutions but none seem to work.
I have tried:
Setting main interface to "Main.storyboard"
Installing all views i.e.: width: any, height: any
Adding print statement to viewDidLoad to state that the view did in fact load (didn't print that the view loaded)
Resetting all content of the iOS simulator
Running on my iPhone
Setting initial view controller
None of these have solved my problem
Make sure in your AppDelegate that you are creating the variable window like so (right after the app delegate class declaration): var window: UIWindow?.
Without this line of code, your views will just never launch and your screen will stay black.
There might be many reasons for blank black view. But first check whether you have the window variable declared in your appDelegate as suggested by #john. If this doesnt work, check in the storyboard whether you have made your first controller as initial view controller.
You can also do this by adding rootviewController as the view controller you want in the window inside application:didFinishLaunchingWithOptions:
May be you use an empty UIViewController(). In my case I set a default value an empty UIViewController()
Related
When my app is started while the user is in a phone call, the whole app is pushed down below the green Phone-call-bar. The root of my app is a UITabViewController and the Tabs now appear partly below the Screen. The worst part of it is that after the phone call is ended, the view now takes up full screen space, but the Tab Bar is still partly below the screen! The even more strange thing is that when the app is started and the user receives a phone call or leaves the app, makes one and return to the app while the call is active, it resizes as expected. (So this only occurs when starting the app from scratch while a call is active)
The only post I could see regarding this was How In-Call status bar impacts UIViewController's view size?
One of the answers suggested changing the Autoresizing mask:
public override func viewDidLoad() {
super.viewDidLoad()
self.view.autoresizingMask = .flexibleHeight
}
In my UITabBarController, but it changed nothing.
Another answer suggested setting wantsFullScreenLayout to false, which is default for regular UIViewControllers but not for UITabBarControllers. However this property was deprecated in iOS 7 and it suggests using edgesForExtendedLayout and extendedLayoutIncludesOpaqueBars instead.
I don't find enough information there to understand how I should solve this problem. Does anyone have an idea?
Note: It would be quite explanatory with some images, but I cannot post those because it's not released now
Try this one:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated);
self.tabBar.invalidateIntrinsicContentSize();
}
If the launch screen looks broken because of an ongoing call, you can fix it by either using a dynamically sized layout or temporarily hiding the status bar.
If you have an older project it is possible you still use launch images, in that case you can switch to a dynamically sized layout by doing as follows. Create a new storyboard with a single view controller that has the Is Initial View Controller checked. Make sure the view controller can handle different heights. Go to the target's general tab (in the project navigator select the top item, then to the right, select the target under Targets) and choose the newly created storyboard as the launch screen file.
If you instead want to temporarily hide the status bar on launch follow the directions on this page:
Hide status bar on launch image
I created my views in code. The starting point is the didFinishLaunchWithOptions function in the Appdelegate class.
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
let controller = ViewController() // create an instance of my ViewController and set it to the rootViewController
window?.rootViewController = controller
I would like to add a launch screen that appears instantly when your app starts up. The launch screen should be quickly replaced with the first screen of the app, giving the impression that your app is fast and responsive. I found some answers that said it is not possible(Is there any way to code the LaunchScreen programmatically). My idea was creating a new launchView and replace it through NSTimer. Isn't there any easier or alternative way ?
Thanks
This is not possible as such as the Launch Screen is not a regular View Controller and it cannot hold any logic. Any animations which are there in the App during startup are handled after the launch Screen has appeared and the animations are in the root view controller as in Twitter app. If you are completely against using launch Screens then an alternative would be make a view in IB and use its screenShot as a splashImage. There is no way as of now to make a launchScreen programatically or to add any logic to it.
After upgrading my project to iOS7
when I do a BACK Button and the UINavigationController goes back to the previous page, an ImageView on the top of the screen shifts down.
I use IB to do my layouts. These are my Simulated Metrics:
I have AutoLayout off. Any ideas on what the issue might be? I wasnt sure if anyone wants to see specific code and I didnt want to clutter up the question with too much code.
Updates: Based on the comment questions, I wanted to make these updates:
In no place in the application .h or .m file do I make any changes to the imageview's sizes or location.
In both the viewDidLoad and viewDidAppear I call a user-defined method called recalculateAll but their is no reference at all to any imageview sizes. Just for trying it out I commented out the entire section and ran the code and it still jumps down.
In my init I do programatically set some imageviews (you see the #132 in what appears to be a bubble) using their x and y's.
Here is a typical navigation I use for moving from the view controller to the tableviewcontroller:
GetTimeOffByType *showTimeOffReport = [[GetTimeOffByType alloc] initWithNibName:#"GetTimeOffByType" bundle:nil];
showTimeOffReport.timeOffType = #"Vacation";
[self.navigationController pushViewController:showTimeOffReport animated:YES];
These are all .xib files, no storyboarding at all. Its basically a view controller which has an embedded UINavigationController with 6 buttons. Each time a button is pressed it pushes a UITableViewController passing different parameters and showing different data. The transition I am using to get back to the original UIViewController is simply the iOS generated BACK button (so no code to show for that)
Update#2 Hopefully this will help someone solve this wierd behavior. So if I were to click on the table view cell on showTimeOffReport to get the cell detail and then using BACK navigate all the way back it doesnt jump down.
Update#3 Ok this is something I just discovered : The issue of jumping down or not is related to the translucency of the UINavigationBar. If you have a Translucent = YES it will start from the top of the window. If you have a translucent = NO it will start from the bottom of the UINavigationBar.
You might try setting the new property on UIViewController edgesForExtendedLayout to UIRectEdgeNone.
Here is a good resource that explains more about how view layouts changed in iOS 7.
See Apple Documentation
If you plan to be backwards compatible you will probably need to do some runtime checks and adjust positioning if the device is not running iOS 7.
This might help you..You can try adding UIViewControllerBasedStatusBarAppearance key and set it's value NO in your info.plist
UIViewControllerBasedStatusBarAppearance = NO
Short version:
I'm alloc/init/retaining a new UIViewController in one UIViewControllers viewDidLoad method, adding the new View to self.view. This usually works, but it seems to mess up orientation change handling of my iPad app.
Longer version:
I'm building a fairly complex iPad application, involving a lot of views and viewcontrollers. After running into some difficulties adjusting to the device orientation, I made a simple XCode project to figure out what the problem is.
Firstly, I have read the Apple Docs on this subject (a small document called "Why won't my UIViewController rotate with the device?"), and while I do believe it has something to do with one of the reasons listed there, I'm not really sure how to fix it.
In my test project I have an appDelegate, a rootViewController, and a UISplitViewController with two custom viewControllers. I use a button on the rootViewController to switch to the splitViewController, and from there I can use a button to switch back to the rootViewController. So far everything is great, i.e. all views adjust to the device orientation.
However, in the right viewController of the splitViewController, I use the viewDidLoad method to initialize some other viewControllers, and add their views to its own view:
self.newViewController = [[UIViewController new] autorelease];
[newViewController.view setBackgroundColor:[UIColor yellowColor]];
[self.view addSubview:newViewController.view];
This is where things go wrong. Somehow, after adding this view, adjusting to device orientation is messy. On startup everything is fine, after I switch to the splitViewController everything is still fine, but as soon as I switch back to the rootViewController it's all over. I have tried (almost) everything regarding retaining and releasing the viewcontroller, but nothing seems to fix it.
As you can see from the code above, I have declared the newViewController as a property, but the same happens if I don't.
Shouldn't I be adding a ViewController's view to my own view at all? That would really mess up my project, as I have a lot of viewControllers doing all sorts of things.
Any help on this would be greatly appreciated...
I had the same problem, seams resolved by removing from the parent view the "autoresize subview" option in IB.
Select the view a then: Inspector -> Attributes (first tab) -> drawing.
What I think is happening is that your new viewcontroller is getting the autorotation calls and probably not handling them. Meanwhile your old viewcontrollers and its views won't get the autorotation calls and will be stuck in whatever orientation they were in.
I can't tell, but I think what you want to do is to make a UIView and add it to your old viewcontroller, instead of making a UIVIewController and adding its view.
I'm working on an iPad app that uses a UISplitView. Inspired by http://blog.blackwhale.at/2010/04/your-first-ipad-split-view-application/, I display a button in my detail view when in portrait mode that shows the popover controller. This works great. However, the appropriate UISplitViewControllerDelegate message is only sent when the device rotates. So, when the app first loads (in portrait mode), my navigation button is not visible.
Is it possible to somehow convince the UISplitViewController to send that message on load or something, or do I need to re-implement my own popover logic to get things working?
Thanks,
-Patrick
We had the exact same issue and it turned out that this thread had the right clues. When comparing our app with the SplitView template, we noticed that the split template does exactly what was mentioned here: set the UISplitViewController as the root view controller in application:didFInishLaunchingWithOptions.
Out previous solution linked the split view controller in the XIB directly to the window. While this works it seems the split view has difficulties getting the startup orientation and the missing button occurs. When we removed the link in the XIB and created it in code in the app delegate, everything ran fine.
That's weird. Maybe you missed something. Take a look at the template based on a splitController. It works fine form very startup no matter in what mode the app was loaded.
did you make sure that your UISplitViewController's view is the only subview of your UIWindow, and that you added it inside the application:didFinishLaunchingWithOptions: method of your app delegate