0

I have created a simple stopwatch following a tutorial on Youtube but I have found that pressing the 'lap' button just gives me the current time the timer is at.

The only way I can think of doing this is having a timer running in the background that prints the time the button is pressed but resets after that.

Is there an easier way?!

This is the first project I have done and I am still getting to grips the with basics.

Here's the lap-related code:

@IBAction func lapReset(sender: AnyObject) {

    if addLap == true {

        laps.insert(stopwatchString, atIndex: 0)
        lapsTableView.reloadData()


    }else {

        addLap = false

        lapresetButton.setImage(UIImage(named: "lapButton.png"), forState: .Normal)

        laps.removeAll(keepCapacity: false)
        lapsTableView.reloadData()


        fractions = 0
        seconds = 0
        minutes = 0

        stopwatchString = "00:00.00"
        stopwatchLabel.text = stopwatchString


    }


}

Thanks, Mike

Mike Rose
  • 11
  • 3
  • http://stackoverflow.com/questions/13155461/creating-a-stopwatch-in-iphone – Babu Lal Jul 29 '15 at 19:31
  • Thanks for that. I had seen it already but it looked as if a big chunk of code had to altered. I was hoping for a small change, haha. Thanks – Mike Rose Jul 29 '15 at 19:44
  • Dear Mike, what is your question? Describe the question in more details please – IamMashed Jul 29 '15 at 20:06
  • Hi, I need my stopwatch app the display "laps" correctly. At the moment, when I press the Lap button it lists the current time - not the time between the lap button being pressed. How could I add this to the code? See this vid: https://youtu.be/JwQvh4CnVJo?t=416 – Mike Rose Jul 29 '15 at 20:37

1 Answers1

0

Solved. I added a separate timer that reset every time I pressed 'lap' and also posted the lap time on the tableview.

Mike Rose
  • 11
  • 3