Cannot retrieve associated object

33 Views Asked by At

I am setting my associated object in my cellForRowAt: method like this:

objc_setAssociatedObject(cell.changeBtn, &self.appointmentHandle, appt, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
cell.changeBtn.addTarget(self, action: #selector(self.changeButtonTouch(sender:)), for: UIControlEvents.touchUpInside)

However, in the button touch method I do this:

func changeButtonTouch(sender:UIButton) {            
    let assObj = objc_getAssociatedObject(sender, &self.appointmentHandle)
    let appt = assObj as! CHRAppointment
    let changeControl = CHRAppointmentConfirmController()
    changeControl.appointment = appt           
}

My associated object there is nil every time. Why is it not retrieving the object properly?

0

There are 0 best solutions below