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!
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)
}
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:
- 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'
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)
view.addSubview(destinationVC.view)
sourceVC.view.addSubview(view)
UIView.animate(withDuration: 2, animations: {
sourceVC.view.transform =
CGAffineTransform(translationX: -sourceVC.view.frame.size.width, y: 0);
}) { completion in
view.removeFromSuperview()
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.
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.
Related Topics
Swift Firebase Using an Unspecified Index
Get the Type of Anyobject Dynamically in Swift
Rotate a Text View and Its Frame in Swiftui
How to Disable "Save to Files" in iOS 11
How to Respond with an Image Using Vapor
How to Stop/Cancel Playsoundfilenamed in Swift
How to Create Apple Watchos5 Complication
Numeric Types Don't Automatically Bridge to Nsnumber in Pure Swift on Ubuntu Linux
Change Notification from Observable Object as a Nested Object in Swiftui
Skshapenode Is Not Responding to Physicsbody
How to Compare Cgpoints in Swift
Check If a Func Exists in Swift
Use of Undeclared Type Autoreleasingunsafepointer Xcode 6 Beta 6
Delay a Repeating Animation in Swiftui with Between Full Autoreverse Repeat Cycles
How to Sum the Numbers(Int16) of Stored Core Data - Swift 3