I basically want to send a known string from a method I am in:
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];
To the callback function, where I can load the sent string in the UIWebview…
-(void) clickedInsidePage:(id) sender{
NSString *websiteString = [[[NSString alloc] initWithString:[((UIControl *) sender) valueForKey:@"website"]] autorelease];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:[NSURL URLWithString:websiteString]];
NSLog(@"visiting: %@",websiteString);
.
.
.
}
But I get an error thrown because the key/Value was not actually set or initialized.
You could have an array of strings, then give the button tag property the index. Then you can extract the tag to get the string:
In your if statement, set the button to match the index:
Then use the index to get the string: