[![enter image description here][2]][2]i want to programm an App with two ViewControllers
第一个对第二个VC执行segue。
第二个VC具有一个具有不同视图的Scrollview。
我用自动排版完成了所有工作,而不用代码
当我运行应用程序时,总是出现错误“其视图不在窗口层次结构中!”。并且无法滚动到底部。我试图找到一些解决方案,但没有任何帮助。
希望有人可以帮助我解决这个问题。
我的第一个VC运行正常的performSegue(“ identifier”,sender)
我的第二个VC的代码是
导入UIKit
类FragenViewController:UIViewController {
var fragen = [Question]()
var highscore = 0
var questionNumber = 0
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var questionLabel: UILabel!
@IBOutlet weak var answerButton1: UIButton!
@IBOutlet weak var answerButton2: UIButton!
@IBOutlet weak var answerButton3: UIButton!
@IBOutlet weak var answerButton4: UIButton!
@IBOutlet weak var forwardButton: UIButton!
@IBOutlet weak var scoreLabel: UILabel!
@IBOutlet weak var currentQuestionLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func answerButton_Tapped(_ sender: UIButton) {
}
}
其余的是通过主故事板拖放
在此处输入图片说明
错误告诉您,您试图在视图层次结构中更改视图之前的内容。
I suspect that you did it in
prepareFor(segue...
which is too early. You need to pass information to the new VC, but only use it after viewDidLoad().I wrote an article about this issue: https://app-o-mat.com/post/ios-how-to-pass-values-to-vc, which will explain it, but for your case you probably just need to move code out of the
init()
of the 2nd VC and intoviewDidLoad()