我基本上想从我所在的方法发送一个已知字符串:
NSString *websiteString;
if(a==0)
websiteString = [[[NSString alloc] initWithString:@"www.google.com"] autorelease];
else
websiteString = [[[NSString alloc] initWithString:@"www.yahoo.com"] autorelease];
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeCustom];
aButton.frame = rct;
// I get thrown in this next line: how do I initialize the Value for key?
[aButton setValue:websiteString forKey:@"website"];
[aButton addTarget:self action:@selector(clickedInsidePage:) forControlEvents:UIControlEventTouchUpInside];
到回调函数,我可以在 UIWebview 中加载发送的字符串...
-(无效)clickedInsidePage:(id)发件人{
NSString *websiteString = [[[NSString alloc] initWithString:[((UIControl *) sender) valueForKey:@"website"]] autorelease];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:[NSURL URLWithString:websiteString]];
NSLog(@"visiting: %@",websiteString);
.
.
.
}
但是我收到一个错误,因为键/值实际上没有设置或初始化。