webView:shouldStartLoadWithRequest:navigationType: not getting called on webkit with youtube video link iphone
I am using webkit to display YouTube videos on iOS4. Upon click on the video it should automatically launch the player and display the vid开发者_开发问答eo, but what's happening is video is rendered in the player but under the webview. What I want to do is make webview's alpha 0 so I'm using delegate
webView:shouldStartLoadWithRequest:navigationType:
But this delegate is not getting called when tapped on the video to launch it. It's otherwise getting called while the first webview itself is launched from the url.
Edit
- (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;
}
- (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];
}
here:
[self.view addSubview:web];
self.view is nil and adding view to nil will notretain your webview.
[web release];
You are releasing webview which is having retain count 0.
try
self.view = web;
[web release];
this will work for you.
精彩评论