Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6931995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:38:59+00:00 2026-05-27T11:38:59+00:00

Sorry for the long question, but I have been stuck on this for days

  • 0

Sorry for the long question, but I have been stuck on this for days and have exhausted all other help.

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 here. 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).

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.

- (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;
    }
}

In videosView.h, I only have the following:

#import <UIKit/UIKit.h>

@interface videosView : UIWebView 
{
}

- (videosView *)initWithStringAsURL:(NSString *)urlString frame:(CGRect)frame;

@end

In videosView.m, I have the following, though I am getting a warning on the initWithFrame line.

- (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 = @"<html><head>\
        <body style=\"margin:0\">\
        <embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
        width=\"%0.0f\" height=\"%0.0f\"></embed>\
        </body></html>";

        // 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

imagesView is made, but has no added code it in currently, as I am just trying to get the videos sorted out first.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:39:00+00:00Added an answer on May 27, 2026 at 11:39 am

    My recommendation:

    1. Use one view controller and have the view controller contain both views. You are already doing that.
    2. You can still use separate files (subclasses of UIView).
    3. Do not use addSubview: and removeFromSuperView:, but rather set these “container” view as hidden as appropriate.
    4. Also, in the segmentedControlChanged method, do all the other necessary switching tasks, such as canceling open URL connections etc.
    5. Do the initialization of the web content of the container views in viewDidLoad rather than in the initializer. Make sure you do not freeze the UI but use asynchronous loading.

    EDIT: Adding subclassing code.

    in SecondViewController.h:

    #include VideosView.h    
    ...
    @property (nonatomic, retain) VideosView *videoView;
    

    in SecondViewController.m

     -(void)viewDidLoad {  
       self.videosView = [[VideosView alloc] init]; 
       // add to superview etc.
    }
    

    Whenever you want to execute view specific code, just call any method you define in VideosView.h and implement in .m.

    [self.videosView playVideo];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for this long post. The question is however small but requires full detail.
im sorry if this has already been covered, i have had a look but
Sorry this is such a long question. Ive been doing lots of research lately
I am really sorry to ask this silly question. I have been onto this
I am sorry that they ask this question has been asked many times but
Sorry this is such a long question but it touches on a general issue
I'm sorry this is a very long question. I'm looking for help from people
I have been a follower for a long time but this is the first
Sorry for a long question and not a very descriptive title, but my problem
This question has disturbed me for a long time. Sorry if it is a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.