Running Segue using code gives a black screen

I'm trying to make segue to another screen using code, but it shows me a black screen using Xcode 7 beta 6. here is my level 1 controller file code

//  ViewController.swift
//  Segue through programming
//

import UIKit

class ViewController: UIViewController{

    @IBAction func buttonPressed(sender: AnyObject) {
        presentViewController(secondController(), animated: true) { () -> Void in

        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}
+4
source share
1 answer

This will only work if it secondControllerprogrammatically creates its presentation. If you want to use a storyboard scene (which is much more common), you can do the following:

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

This obviously assumes that you have specified the storyboard identifier for the destination scene.

enter image description here

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

enter image description here

, segue :

enter image description here

segue:

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

All Articles