我正在尝试使用代码对另一个屏幕进行segue,但它使用
Xcode 7 beta 6向我显示黑屏.
这是我的第一个视图控制器文件代码
这是我的第一个视图控制器文件代码
// 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. } }
解决方法
这仅在secondController以编程方式创建其视图时才有效.如果要使用故事板场景(更常见),可以执行以下操作:
@IBAction func buttonpressed(sender: AnyObject) { let controller = storyboard?.instantiateViewControllerWithIdentifier("foo") presentViewController(controller!,animated: true,completion: nil) }
这显然假设您已为目标场景指定了故事板标识符.
或者,您可以通过控制从第一个场景顶部的视图控制器图标拖动到第二个场景,在IB中的两个场景之间创建一个segue:
然后给那个segue自己的故事板id:
然后,您可以以编程方式调用segue:
@IBAction func buttonpressed(sender: AnyObject) { performSegueWithIdentifier("bar",sender: self) }