Screen Goes Black After Segue

Screen goes black after segue

I have solved the problem! the problem was the order in which the functions were being called.

I realised not that the page was being set up too fast for firebase so I now call the function earlier! in the view will appear

override func viewWillAppear(_ animated: Bool) {


Thanks to all who helped!

Swift performSegueWithIdentifier shows black screen

I've build your app and everything works, maybe you've missed something, here is my solution (Note: Code is in Swift 3.0, but should be easy to adopt it to Swift 2.*):

The storyboard:

Sample Image

Set the segueToTraits identifier:

Sample Image

Set the TraitViewController class as custom class in the storyboard:

Sample Image

The view controller with the buttons:

import UIKit

class ViewController: UIViewController {

let boyGender = "boy"
let girlGender = "girl"
var selectedGender: String?

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "segueToTraits"{
if let gender = self.selectedGender {
let traitVC = segue.destination as? TraitViewController
traitVC!.gender = gender

func sendGenderToTraitsView(gender : String?){
performSegue(withIdentifier: "segueToTraits", sender: self)


@IBAction func button1(sender: UIButton) {
selectedGender = boyGender
self.sendGenderToTraitsView(gender: selectedGender)

@IBAction func button2(sender: UIButton) {
selectedGender = girlGender
self.sendGenderToTraitsView(gender: selectedGender)


The trait view controller:

import UIKit

class TraitViewController: UIViewController {

var gender: String = ""

override func viewDidLoad() {

print("gender: \(gender)")



Sample Image

You can find the sample project here

Performing Segue using code gives shows black screen

This will only work if secondController programmatically creates its view. If you want to use a storyboard scene (which is far more common), you can do the following:

@IBAction func buttonPressed(sender: AnyObject) {
let controller = storyboard?.instantiateViewControllerWithIdentifier("foo")
presentViewController(controller!, animated: true, completion: nil)

That obviously assumes that you've specified a storyboard identifier for the destination scene.

Sample Image

Or, you can created a segue between the two scenes in IB by control dragging from the view controller icon at the top of the first scene to the second scene:

Sample Image

and then give that segue its own storyboard id:

Sample Image

Then you can invoke the segue programmatically:

@IBAction func buttonPressed(sender: AnyObject) {
performSegueWithIdentifier("bar", sender: self)

Sporadic black screen when performing segue in iOS 9.2.1 / XCode 7.2

I've solved it. Checking the memory usage turned out to be quite useful.

The grey area was supposed to be filled by a large background with lines drawn. It turns out the naive implementation of drawBackground causes the memory size to balloon to over 200MB. I replaced it with a CSTiledLayer, and now it takes a few MB instead.

Black screen when segueing to UITableViewController in swift

There is still no logical reason as to why this happened - but doing a full clean of the build folders has stopped it happening. So if you're having the same issue, try this:

  1. When in Xcode, go to the top bar and select 'Product'
  2. When the list appears, you'll see the 'Clean' option.
  3. Hold down the alt key and the option will change to 'Clean build folder'
  4. Click 'Clean build folder'

Custom Segue to UINavigationController shows black screen

Ok let's go through your destination view controller because it appear to be black:
You're doing a reference to your destination view controller:

UINavigationController *destinationViewController = self.destinationViewController;

Then you want to animate it with

destinationViewController.topViewController.view.transform = ...

So you operate on view that is not shown on the screen yet.

Then after animation you're doint this:

[destinationViewController.topViewController.view removeFromSuperview]; // remove from temp super view

So you're actually here removing UIViewController superview not "temp" superview!

So when you in the next step

[sourceViewController presentViewController:destinationViewController animated:NO completion:NULL]; // present VC

Doing that your destinationViewController has no view whatsoever, so it appear as black screen.

To fix it copy a view animate and remove when destination vc is loaded. I believe that you had exactly this in mind when I look at your code.

So the base idea is:

override func perform() {
let sourceVC = self.source
let destinationVC = self.destination
let view : UIView = UIView()
view.frame = CGRect(x: sourceVC.view.frame.size.width, y: 0, width: sourceVC.view.frame.size.width, height: sourceVC.view.frame.size.height)

UIView.animate(withDuration: 2, animations: {
sourceVC.view.transform =
CGAffineTransform(translationX: -sourceVC.view.frame.size.width, y: 0);

}) { completion in
sourceVC.present(destinationVC, animated: false, completion: nil)

Of course code will be different when u use autolayout yes or no... But you should get from it a basic idea.

Sample Image

NavigationController in swift leads to a black screen

Probably the segue you picked: mode & transition.

Are you certain you only have a single segue? It is possible to have overlapping segues, which do not show up clearly in Interface Builder.


Is there a way we can see all our segues?

  1. Open the Storyboard in its new window
  2. Show Document Outline (leftmost pane)
  3. Show Attribute Inspector (rightmost pane)
  4. Select each View Controller Scene in the Document Outline. The Segues are listed at the bottom. You can inspect Identifier and Segue in the Attribute Inspector.

Sample Image

Related Topics

Leave a reply