I hope You are well, I’ve been working a few weeks on iphone and at the moment I have a problem try to open a safari with a url, I have a json file that come a url which is dinamic.
here I leave the code.
- (void) loadFiles {
NSArray *_json = [[[self getDataFromJson] objectAtIndex:0] retain];
if ([_json count] > 0)
{
for (int i = 0; i < [_json count]; i++)
{
NSDictionary *file = [_json objectAtIndex:i];
UIImage *buttonImage = [UIImage imageNamed:@"btn.png"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setImage:buttonImage forState:UIControlStateNormal];
[button addTarget:self action:@selector(openBrowser:) forControlEvents:UIControlEventTouchUpInside];
//works but i have warnings
button.tag = [file objectForKey:@"linkURL"] ;
CGRect frame = CGRectZero;
frame.size = buttonImage.size;
button.frame = frame;
NSString *name = [file objectForKey:@"name"];
NSString *description = [file objectForKey:@"description"];
//Create Box
}
}
}
- (void) openBrowser:(id)sender
{
NSString *url = ((UIControl *) sender).tag;
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url] ];
}
I need to open from the UIButtom an URL without complaint .
Any suggestion or help thank you.
Cheers
Subclass
UIButtonand add a property to store the URL.and then you continue with your code: