Example:
Static Const CharKrepresentedobject;-(Ibaction) DoSomething: (ID) Sender {Uialertview*alert =[[Uialertview alloc] Initwithtitle:@"Alert"Message:nilDelegate: Self cancelbuttontitle:@"OK"Otherbuttontitles:nil]; Objc_setassociatedobject (Alert,&krepresentedobject, sender, objc_association_retain_nonatomic); [Alert show]; }- (void) Alertview: (Uialertview *) Alertview Clickedbuttonatindex: (Nsinteger) buttonindex {UIButton*sender =Objc_getassociatedobject (Alertview,&krepresentedobject); Self.buttonLabel.text=[[Sender Titlelabel] text];}
Where: void Objc_setassociatedobject (ID object, const void *key, ID value, Objc_associationpolicy policy)
The above parameters are: source object, keyword (unique static variable), associated object, association policy
ID objc_getassociatedobject (ID object, const void *key)
The above parameters are: source object, keyword (unique static variable), return the associated object
So click on the different button trigger Uialertview Click event can change the corresponding button properties, very convenient
Ios-runtime-objc_setassociatedobject (associated objects and values)