I have a UIAlertView (several, in fact), and I\'m using the method -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
to trigger
Probably the quickest way to associate an object with an arbitrary other object is to use objc_setAssociatedObject
. To use it correctly, you need an arbitrary void *
to use as a key; the usual way to do that is to declare a static char fooKey
globally in your .m file and use &fooKey
as the key.
objc_setAssociatedObject(alertView, &secretStringKey, mySecretString, OBJC_ASSOCIATION_RETAIN);
objc_setAssociatedObject(alertView, &intKey, [NSNumber numberWithInt:myInt], OBJC_ASSOCIATION_RETAIN);
Then use objc_getAssociatedObject
to retrieve the objects later.
NSString *mySecretString = objc_getAssociatedObject(alertView, &secretStringKey);
int myInt = [objc_getAssociatedObject(alertView, &intKey) intValue];
Using OBJC_ASSOCIATION_RETAIN, the values will be retained while attached to the alertView
and then automatically released when alertView
is deallocated.