我在我的cellForRowAt:
方法中设置我的关联对象,如下所示:
objc_setAssociatedObject(cell.changeBtn, &self.appointmentHandle, appt, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
cell.changeBtn.addTarget(self, action: #selector(self.changeButtonTouch(sender:)), for: UIControlEvents.touchUpInside)
但是,在按钮触摸方法中,我这样做:
func changeButtonTouch(sender:UIButton) {
let assObj = objc_getAssociatedObject(sender, &self.appointmentHandle)
let appt = assObj as! CHRAppointment
let changeControl = CHRAppointmentConfirmController()
changeControl.appointment = appt
}
我的关联对象nil
每次都有。为什么它不能正确检索对象?