URL öffnen mit UIButton

Ich hoffe, Sie sind gut, ich arbeite seit ein paar Wochen auf dem iphone und im moment habe ich ein problem versuchen, öffnen Sie ein safari-mit einer url, ich habe eine json Datei, einen url, die ist dynamisch.

hier lasse ich den 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] ];
}

Brauche ich um zu öffnen aus der UIButtom eine URL ohne Beanstandung .
Jede Anregung oder Hilfe danke.
Cheers

  • Die tag-Eigenschaft ist eine Ganzzahl, Sie können nicht speichern Sie eine URL gibt.
InformationsquelleAutor ron | 2011-01-20
Schreibe einen Kommentar