0

I want the app to move to the end screen once the last index of the array is reached. This is what I have for the code where "endWorkout" is the modal segue identifier:

if (index < workouts2.endIndex-1) {
        index++;}

else {
        timerLabel.pause();
        timerLabel.reset();
        performSegueWithIdentifier("endWorkout", sender: self)
        println("Hello")}

The app transitions to the End Workout screen just fine but I get a non-stop loop of the following error in the xcode console: whose view is not in the window hierarchy! Hello

It also keeps printing out the print statement "Hello" which should be printed only once. The other solutions I've read suggest that the performSegueWithIdentifier should be in the method "viewDidAppear" but I need it to be inside the conditional block in this particular method since the screen should appear at the end of the entire workout routine. What am I doing wrong? Thanks!

blob12
  • 141
  • 2
  • 12

2 Answers2

3

the message "whose view is not in the window hierarchy" because the code still execute while your already transition to another view. try call return or break after performSegueWithIdentifier to stop the loop

xmhafiz
  • 3,482
  • 1
  • 18
  • 26
  • I added return and it worked! Can't believe I didn't try it before posting here. Thanks! – blob12 Jul 11 '16 at 07:11
  • Just to expand a little further when you present another viewcontroller modally the existing view controller object (the one that is presenting) is still there beneath the modal view controller (the one being presented) thus if you have a loop like so it will continue to exectue and thats what happend here. – Blake Lockley Jul 12 '16 at 01:19
0

Try to add (break;) after performSegueWithIdentifier("endWorkout", sender: self).

Abd Aboudi
  • 331
  • 2
  • 7