Search code examples
iosswiftsegueuibarbuttonitemviewdidload

viewDidEnd() method possible in swift?


I have a UIBarButtonItem that performs a segue, but I need to invalidate an NSTimer when this button is pressed and the segue is performed. Unfortunately, it doesn't seem you can create a touch up inside method with a UIBarButtonItem. This being said, how could I invalidate this timer when this view is exited or this button is tapped? Possibly some viewDidEnd() method? Please bear with me, I am new to swift and coding.


Solution

  • A good time to invalidate timers is probably going to be in viewWillDisappear(). You can override it like so in your view controller:

    override func viewWillDisappear(animated: Bool) {
       // Your code here
    }