2
votes

I have a strange problem with Core Plot Realtime. I have a UIButton that starts and stops a timer that up-dates the plot data. I do keep a history of the previous points and only display the last 150 values. It all works great. Now when I then change the text for the UIButton based on the timer being on and setting it to off, the plot resets to its initial first 150 values. when I restart the timer it picks up where it left off at the end of the data. The code looks like this:

@IBOutlet weak var pause: UIButton!

@IBAction func pausePlay() {
    if isPaused  {
        startGraphUpDates()
        isPaused = false
        pause.setTitle("⏸", for: .normal)

    } else {
        stopGraphUpDates()
        isPaused = true
        pause.setTitle("▶️", for: .normal) // This is the statement that seems to cause the problem.
     }
}

Any thoughts would be appreciated

1
Is isPaused set to true during initialization or does the timer start immediately? What's the code in startGraphUpDates() and stopGraphUpDates()? - Eric Skroch
isPaused is initialized when declared as: var isPaused: Bool = false when the ViewController loads. The startTimer() function is called in viewDidLoad() and I see that I am setting up the plot in viewDidLayoutSubviews() . Here are the functions that start and stop the timer used to update the plot: - Michael Jay
func startGraphUpDates() { // Set up a timer update graph self.graphUpdateTimer = Timer.scheduledTimer(timeInterval: (1.0 / frameRate), target: self, selector: #selector(newData), userInfo: nil, repeats: true) } func stopGraphUpDates() { self.graphUpdateTimer.invalidate() } - Michael Jay

1 Answers

0
votes

This was a simple fix. I was initializing the plot in:

override func viewDidLayoutSubviews() {
  super.viewDidLayoutSubviews()
  initPlot()
}

I should have initialized the plot in:

override func viewDidLoad() {
  super.viewDidLoad()
  initPlot()
}