Swift Performseguewithidentifier Shows Black Screen

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() {
super.viewDidLoad()

print("gender: \(gender)")
}

}

Result:

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)
}

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.

Edit

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

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) {
print("Done")
super.viewWillAppear(animated)

self.loadDataFromFirebase()
}

Thanks to all who helped!

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'


Related Topics



Leave a reply



Submit