webView:shouldStartLoadWithRequest:navigationType:没有使用youtube视频链接iphone调用webkit

时间:2010-09-23 10:44:32

标签: iphone uiwebview

我正在使用webkit在iOS4上显示youtube视频。点击视频后,它应自动启动播放器并显示视频,但正在发生的是视频在播放器中呈现,但在webview下。我想做的是使webview的alpha 0,所以我使用委托

      webView:shouldStartLoadWithRequest:navigationType:

但是当点击视频启动它时,这个代表没有被调用。当第一个webview本身从网址启动时,它会被调用。

编辑:

- (void)loadView {
[super loadView];

activityIndicatorView = [[ActivityIndicator alloc] init];

web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
web.delegate = self;
NSString *videoUrl = @"http://www.youtube.com/watch?v=";
NSString *fullVdoUrl = [videoUrl stringByAppendingFormat:_videoUrl];

NSString *urlAddress = [NSString stringWithFormat:fullVdoUrl];   
NSURL *url = [NSURL URLWithString:urlAddress];           //Create a URL object.
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];            //URL Requst Object
[web loadRequest:requestObj];              //Load the request

[self.view addSubview:web];
[web release];

}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
[activityIndicatorView.view removeFromSuperview];
web.alpha = 1.0;
}

- (void)webViewDidStartLoad:(UIWebView *)webView {     
[self.view addSubview:activityIndicatorView.view];
}

-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
web.alpha = 0.0;
return YES;
}

有人可以帮忙吗?这真的很紧急。

提前完成。

1 个答案:

答案 0 :(得分:1)

- (void)loadView {
[super loadView];

activityIndicatorView = [[ActivityIndicator alloc] init];

web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
web.delegate = self;
NSString *videoUrl = @"http://www.youtube.com/watch?v=";
NSString *fullVdoUrl = [videoUrl stringByAppendingFormat:_videoUrl];

NSString *urlAddress = [NSString stringWithFormat:fullVdoUrl];   
NSURL *url = [NSURL URLWithString:urlAddress];           //Create a URL object.
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];            //URL Requst Object
[web loadRequest:requestObj];              //Load the request

[self.view addSubview:web];
[web release];

}

这里:

[self.view addSubview:web];

self.view为零,将视图添加到nil将无法获取您的网页视图。

[网络发布];

您正在发布保留计数为0的webview。

self.view = web;
[web release];

这对你有用。

相关问题