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:
Set the segueToTraits identifier:
Set the TraitViewController class as custom class in the storyboard:
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:
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.
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:
and then give that segue its own storyboard id:
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?
- Open the Storyboard in its new window
- Show Document Outline (leftmost pane)
- Show Attribute Inspector (rightmost pane)
- 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.
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:
- When in Xcode, go to the top bar and select 'Product'
- When the list appears, you'll see the 'Clean' option.
- Hold down the alt key and the option will change to 'Clean build folder'
- Click 'Clean build folder'
Related Topics
How to Loop Through an Array from the Second Element in Elegant Way Using Swift
How Should You Handle Closure Arguments for Uialertaction
How to Create a Multi Line Text Field in Swiftui for MACos
Injecting a New Stylesheet into a Website via Uiwebview Using iOS8 Swift Xcode 6
Find Multiple Quoted Words in a String with Regex
How to Check If a Property Has Been Set Using Swift Reflection
How to Generate a Binding for Each Array Element
Nsjsonserialization Not Working as Expected in a Playground
Swift - Get File Path of Currently Opened Document in Another Application
For Loop for Dictionary Don't Follow It's Order in Swift
Arkit -Drop a Shadow of 3D Object on the Plane Surface
Is There a Preferred Technique to Prohibit Pasting into a Uitextfield
How to Cast an Any Value with Nil in It to a Any
How to Use a Variadic Closure in Swift
Add Skreferencenode/Skscene to Another Skscene in Spritekit
Dynamic/Runtime Dispatch in Swift, or "The Strange Way Structs Behave in One Man's Opinion"
Swift Minimum Implementation for Types Conforming to Protocols with Default Implementations