ios - Where should I add and remove observer in UICollectionViewCell? -


there missing in understanding of uicollectionviewcell lifecycle.

when uicollectionviewcell created , configured add observer on 1 of properties

func setcelldetails(somedetails:someobject) {     ...     self.someproperty.addobserver(self, forkeypath: "objectproperty", options: .new, context: nil)     ... } 

i remove observer on prepareforreuse

override func prepareforreuse() {     super.prepareforreuse()     self.someproperty.removeobserver(self, forkeypath: "objectproperty") } 

but when jumping between tabs of application , influence objectproperty cell not effected. debugged code , found when changing tabs, prepareforreuse of cell called observer removed , never added because cell setup function not called. maybe should add or remove observer in other functions?


i tried put removeobserver in deinit , crashes following error:

terminating app due uncaught exception 'nsinternalinconsistencyexception', reason: 'an instance 0x12eb89dd0 of class observedobject deallocated while key value observers still registered it. current observation info: nskeyvalueobservationinfo nskeyvalueobservance observer: .. key path: objectproperty

i thought maybe not put removeobserver in anyplace. produced same error.

what should do? should put it?

try remove observer collection view's delegate method:- collectionview:didenddisplayingcell:foritematindexpath:


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -