开发者

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) {
    开发者_如何学C       //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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜