Let say I have two view controllers, View controller A and View controller B
class ViewControllerA: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// it runs this function every 5 seconds
Timer.scheduledTimer(5, target: self,selector: #selector(ViewControllerA.printNumber), userInfo: nil, repeats: true)
}
@IBAction func callViewControllerBButtonClicked(_ sender: UIButton) {
if let vc = self.storyboard?.instantiateViewController(withIdentifier: "ViewControllerBID") as? ViewControllerB {
self.present(vc, animated: true, completion: nil)
}
}
func printNumber() {
print(0)
}
}
Whenever someone clicks callViewControllerBButtonClicked()
button, it will instantiate a new view controller which is ViewControllerB and sort of present it on top of ViewControllerA. The problem that I'm facing right now is even though I'm already on ViewControllerB, it still runs this function
Timer.scheduledTimer(5, target: self,selector: #selector(ViewControllerA.printNumber), userInfo: nil, repeats: true)
How do I pop ViewControllerA?