如何在SecondViewController
方法内与ViewController
同时加载viewDidLoad()
?
Segue的类型为Sheet
。
import Cocoa
class ViewController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.performSegue(withIdentifier: "secondVC", sender: self)
}
func prepareforSegue(segue: NSStoryboardSegue, sender: Any?) {
if let identifier = segue.identifier, identifier == "secondVC" {
_ = segue.destinationController as? SecondViewController
}
}
}
答案 0 :(得分:2)
此
self.performSegue(withIdentifier: "secondVC", sender: self)
在viewDidLoad
内部不起作用,请考虑将其包装在viewDidAppear
中的Dispatch-after或bool标志内部
DispatchQueue.main.asyncAfter(deadline:.now() + 2 ) {
self.performSegue(withIdentifier: "secondVC", sender: self)
}
OR
var once = true
override func viewDidAppear() {
super.viewDidAppear()
if once {
self.performSegue(withIdentifier: "secondVC", sender: self)
once = false
}
}