#import "ViewController.h"
#import <objc/runtime.h>
static char alertInfoKey;
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
NSString* dataYouWantToPass = @"some info";
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"hello" message:@"miss-chalk" delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"YES", nil];
[alert show];
objc_setAssociatedObject(alert, &alertInfoKey, dataYouWantToPass, OBJC_ASSOCIATION_RETAIN);
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSString* data = objc_getAssociatedObject(alertView, &alertInfoKey);
NSLog(@"%@",data);
}
@end
运行结果:
2013-09-17 14:34:05.902 objc_setAssociatedObject--Test[2561:c07] some info