[英]Performing Segue using code gives shows black screen
我正在嘗試使用代碼對另一個屏幕做一個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)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.