views:

59

answers:

2

Hi all ,I import WebView.h to my project,and it only has a simple IBOutlet UIWebView *myWebView ;

How to Open a WebView when I press the button in the alert view ?

here is how I define alert view button response

- (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
        }
    }
}

thanks for all any reply or answer !

note:I can pop up my Webview , but How to init a URL address to the webview I wanna call ?

A: 

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];
GhostRider
.......sorry I don't know what you mean ? about [[videolistArray objectAtIndex:indexPath.row] valueForKey:@"video"] ;
WebberLai
that is string of url i save url string videolistArray
GhostRider
thank you !!!!!
WebberLai
+1  A: 
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];
        }
    }
}
KingofHeaven
I try this answer now,please wait.
WebberLai
Excuse me,where should I place UIWebView *webView=[[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,480);[self.view addSubView:webView]; ???I put this in -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{...
WebberLai
OK...I figure about warning "UIView may not respond to addSubView" -> addSubView:webview instead->addSubview
WebberLai
this is the right answer,but some warning will occur if you didn't add one more "]" to UIWebView *webView=[[UIWebView alloc] initWithFrame:CGRectMake(0,0,320,480); and replace addSubView to addSubview
WebberLai