0

I have a timer in UICollectionViewCell,

timer = Timer.scheduledTimer(timeInterval: 5, target: self, selector: #selector(shakeView), userInfo: nil, repeats: true)

now I want to remove timer when controller disapper, but cell deinit not called

Norman
  • 7
  • 3
  • I'd start by looking at [UICollectionViewDelegate#collectionView(_:didEndDisplaying:forItemAt:)](https://developer.apple.com/documentation/uikit/uicollectionviewdelegate/1618006-collectionview), which should allow you to stop the timer when the cell is no longer been displayed - remember, a cell can still be "displayed" even when it's off the screen and has to do with performance. If the timer is anchored to the controller itself, then you should consider using `viewWill/DidDisappear` itself – MadProgrammer Apr 25 '21 at 05:09
  • Check in this link i post a code for Timer in UITableviewCell : https://stackoverflow.com/questions/40350895/multiple-timers-in-uitableviewcell-swift. Try same logic for UICollectionViewCell. – Hardik Thakkar Apr 26 '21 at 13:36

1 Answers1

0

Deinit method is not called because it has retain cycle. Check all the closures and make sure you use weak self or unowned self.

linh lê
  • 102
  • 5