简体   繁体   中英

IPhone SDK : how to open a Webview when touch a button in Alert view?

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

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

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];
        }
    }
}
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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM