我希望应用程序在达到阵列的最后一个索引后移动到结束屏幕。这就是我所拥有的代码,其中" endWorkout"是模态segue标识符:
if (index < workouts2.endIndex-1) {
index++;}
else {
timerLabel.pause();
timerLabel.reset();
performSegueWithIdentifier("endWorkout", sender: self)
println("Hello")}
应用程序转到End Workout屏幕就好了,但我在xcode控制台中得到了以下错误的不停循环:其视图不在窗口层次结构中! 你好
它还不断打印出印刷声明&#34;你好&#34;应该只打印一次。我读过的其他解决方案表明performSegueWithIdentifier应该在方法&#34; viewDidAppear&#34;但我需要它在这个特定方法的条件块内,因为屏幕应该出现在整个锻炼程序的末尾。我究竟做错了什么?谢谢!
答案 0 :(得分:2)
消息&#34;其视图不在窗口层次结构中&#34;因为代码仍然在您已经转换到另一个视图时执行。尝试在Public Class Form1
Delegate Function delegateSum(a As Integer, b As Integer) As Integer
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim s As New delegateSum(AddressOf sum1)
s += AddressOf sum2 'Here is the error, that is "Expression does not produce a value"
End Sub
Public Function sum1(x As Integer, y As Integer) As Integer
Return x + y
End Function
Public Function sum2(x As Integer, y As Integer) As Integer
Return x + y
End Function
End Class
之后调用return
或break
来停止循环
答案 1 :(得分:0)
尝试在performSegueWithIdentifier(&#34; endWorkout&#34;,sender:self)之后添加(break;)。