Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIWebView modal YouTube player "Done" button action

In my iPhone app, I'm presenting a modal view controller from a home screen with a UIWebView that displays an "inline" embedded YouTube video using this:

UIWebView *youTubeWV = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 220)];
        [youTubeWV loadRequest:[NSURLRequest requestWithURL:sourceURL]];
        //NSString *youTubeVideoHTML = [NSString stringWithFormat:@"<embed id=\"yt\" src=\"http://www.youtube.com/watch?v=CadgUJRZfEE\" type=\"application/x-shockwave-flash\" width=\"320\" height=\"220\"></embed>"];
        NSString *youTubeVideoHTML =@"<html><head>"
        "<meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 220\"/></head>"
        "<body style=\"background:#FFFFF;margin-top:0px;margin-left:0px\">"
        "<div><object width=\"320\" height=\"220\">"
        "<param name=\"wmode\" value=\"transparent\"></param>"
        "<embed src=\"http://www.youtube.com/v/W-nzUoaI2Ss?f=user_favorites&app=youtube_gdata\""
        "type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"320\" height=\"220\"></embed>"
        "</object></div></body></html>";
        [youTubeWV loadHTMLString:youTubeVideoHTML baseURL:nil];
        [self.view addSubview:youTubeWV];

The video is displayed without problem in the modal view "quicktime player" that shows. However, when I tap "Done" to close the second modal, I get kicked back to the very first screen, bypassing my first modal view. And in my home screen, now all the buttons don't work. Strange!

UPDATE: I removed the modal transition from my home screen and made it a "pushViewController" instead, and now everything functions properly. So it's an issue of the YouTube player dismiss 2 modals at the same time. How can this be fixed?

Any ideas?

like image 617
quantum Avatar asked Feb 03 '23 18:02

quantum


1 Answers

I'm not sure but it seems that after the "done" button is pressed and the Player is closed the control returns to the root view controller, in your case that's your first screen.

For exaple in my application I have an UITabBarController as my rootViewController, in my AppDelegate I have something like this:

self.window.rootViewController = self.myTabBarController;

So that's the reason why my tabBarController (my first screen) always was presented after pressing the "done" button.

I solved this setting my Modal View as my rootViewController after presenting it.

Try this after presenting your modal view:

MyAppDelegate *appDelegate = (MyAppDelegate *) [[UIApplication sharedApplication] delegate];
[self presentModalViewController: myModalViewController animated: YES];
[self.appDelegate.window setRootViewController: myModalViewController];

NOTE: After dismissing the modal view you must restore the root view controller doing

In my case:

self.appDelegate.rootViewController = self.appDelegate.myTabBarController;

Hope it helps

like image 85
IsaacCisneros Avatar answered Feb 13 '23 05:02

IsaacCisneros