2010-10-14 5 views
0

importer WebView.h à mon projet, et il a un simple IBOutlet UIWebView *myWebView ;IPhone SDK: comment ouvrir un Webview lorsque vous appuyez sur un bouton dans la vue Alert?

Comment ouvrir un WebView lorsque j'appuie sur le bouton dans l'affichage des alertes?

voici comment je définir la réponse bouton d'alerte vue

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ 
    if ([alertView tag]==0) { 
     if (buttonIndex == 1) 
     { 
      //Open WebView with URL string1 
     } 
     if (buttonIndex == 2) { 
      //Open WebView with URL string2 
     } 
    } 
} 

Note: Je peux pop mon Webview, mais comment initialiser une adresse URL au WebView Je veux appeler?

+0

http://www.youtube.com/watch?v=PVESHBfuXrU&feature=related –

+0

cette chanson me fait sentir que funk ... pas de code .... –

Répondre

1
UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,480)]; 
[self.view addSubview:webView]; 

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ 
    if ([alertView tag]==0) { 

     NSURLRequest *urlRequest; 
     NSURL *urlforWebView; 

     if (buttonIndex == 1) 
     { 
      urlforWebView = [NSURL URLWithString:@"http://www.google.com"]; 
      urlRequest = [NSURLRequest requestWithURL:urlforWebView]; 
      [webView loadRequest:urlRequest]; 
     } 
     if (buttonIndex == 2) 
     { 
      urlforWebView = [NSURL URLWithString:@"http://www.yahoo.com"]; 
      urlRequest = [NSURLRequest requestWithURL:urlforWebView]; 
      [webView loadRequest:urlRequest]; 
     } 
    } 
} 
+0

J'essaie cette réponse maintenant, veuillez patienter. –

+0

Excusez-moi, où dois-je placer UIWebView * webView = [[UIWebView alloc] initWithFrame: CGRectMake (0,0,320,480); [self.view addSubView: webView]; Je mets ceci dans - (void) alertView: (UIAlertView *) alertView clickedButtonAtIndex: (NSInteger) buttonIndex {... –

+0

OK ... Je pense à propos de l'avertissement "UIView ne répond pas à addSubView" -> addSubView: webview à la place -> addSubview –

0
web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)]; 

NSString *urlAddress = [[videolistArray objectAtIndex:indexPath.row] valueForKey:@"video"] ; 


NSURL *url = [NSURL URLWithString:urlAddress]; 


NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; 
[web loadRequest:requestObj]; 
[self.view addSubview:web]; 
+0

...... .sorry Je ne sais pas ce que tu veux dire? à propos de [[videolistArray objectAtIndex: indexPath.row] valueForKey: @ "video"]; –

+0

c'est une chaîne d'url je sauvegarde url string videolistArray – GhostRider

Questions connexes