Note that there are some explanatory texts on larger screens.

plurals
  1. POUISegmented Controller to load one view with a few Youtube UIWebViews and another view with Images
    text
    copied!<p>Sorry for the long question, but I have been stuck on this for days and have exhausted all other help.</p> <p>Currently, I have a tab bar application with four tabs. In the second tab (SecondViewController), I have a segmented controller at the top that should switch between "videos" and "images". The videos page should have around 5 youtube videos loaded in UIWebView using the code <a href="http://iphonedevelopertips.com/video/display-youtube-videos-without-exiting-your-application.html" rel="nofollow">here</a>. The images view should contain around 5 thumbnails that, when clicked on, open into a larger picture. My problem is that I have tried out many different ways of accomplishing this, and none seem to work to any extent. Really the main thing I am looking for here is the recommended way of going about switching between two views using a segmented controller and if it is possible to load the views from different files (videosView.h/m and imagesView.h/m). </p> <p>In SecondViewController.m, I have the app respond to the UISegmentedController using the following, though I have absolutely no idea if this is even close to correct.</p> <pre><code>- (IBAction)segmentedControlChanged { switch (segmentedControl.selectedSegmentIndex) {case 0: [self.view addSubview:videosView.view]; [imagesView.view removeFromSuperview]; NSLog(@"1"); break; case 1: [self.view addSubview:imagesView.view]; [videosView.view removeFromSuperview]; NSLog(@"2"); break; default: break; } } </code></pre> <p>In videosView.h, I only have the following:</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface videosView : UIWebView { } - (videosView *)initWithStringAsURL:(NSString *)urlString frame:(CGRect)frame; @end </code></pre> <p>In videosView.m, I have the following, though I am getting a warning on the initWithFrame line. </p> <pre><code>- (videosView *)initWithStringAsURL:(NSString *)urlString frame:(CGRect)frame; { if (self = [super init]) { // Create webview with requested frame size self = [[UIWebView alloc] initWithFrame:frame]; // HTML to embed YouTube video NSString *youTubeVideoHTML = @"&lt;html&gt;&lt;head&gt;\ &lt;body style=\"margin:0\"&gt;\ &lt;embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \ width=\"%0.0f\" height=\"%0.0f\"&gt;&lt;/embed&gt;\ &lt;/body&gt;&lt;/html&gt;"; // Populate HTML with the URL and requested frame size NSString *html = [NSString stringWithFormat:youTubeVideoHTML, urlString, frame.size.width, frame.size.height]; // Load the html into the webview [self loadHTMLString:html baseURL:nil]; } return self; } @end </code></pre> <p>imagesView is made, but has no added code it in currently, as I am just trying to get the videos sorted out first. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload