我正在开发一个iOS测验应用程序,如果用户选择了错误的答案,它会转到错误的答案视图。但是在我当前的代码中,当我运行模拟器并单击错误的答案选项时,我得到了
由于未捕获的异常而终止应用 ' NSInvalidArgumentException',原因:'接收者 ()没有segue 标识符' wrongViewSegue'' ***首先抛出调用堆栈:
并且模拟器结束。如果我没有收到错误,并且在用户选择了错误的答案选项后显示错误的答案视图,我该怎么做呢?
这是我的代码:
//wrong view segue
func wrongSeg() {
performSegue(withIdentifier: "wrongViewSegue", sender: self)
}
//variables
var rightAnswerBox:UInt32 = 0
var index = 0
//Question Label
@IBOutlet weak var questionLabel: UILabel!
//Answer Button
@IBAction func buttonAction(_ sender: AnyObject) {
if (sender.tag == Int(rightAnswerBox)) {
//removes asked question
print ("Correct!")
}
else if (sender.tag != Int(rightAnswerBox)) {
print ("Wrong!")
wrongSeg()
}
randomQuestion()
}
override func viewDidAppear(_ animated: Bool)
{
questionWithAnswers()
}
func questionWithAnswers() {
//random question function
randomQuestion()
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
答案 0 :(得分:3)