无法检索关联的对象

时间:2017-04-03 19:08:15

标签: swift associated-object

我在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。为什么没有正确检索对象?

0 个答案:

没有答案