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 6229967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:39:46+00:00 2026-05-24T09:39:46+00:00

I am new to iPhone programming and trying to grasp the concept of RootViewController.

  • 0

I am new to iPhone programming and trying to grasp the concept of RootViewController.

Scenario:

I have 3 views

  1. RootViewController – Parent View
  2. SportsViewController – Sub View 1
  3. CricketViewController – Sub View 2

Both the subview have to be in FullScreenMode, so tab-bar or navigation bar cannot be used.

At first, Sub View 1 is loaded which is having some content and a DONE button on it.
Once user press DONE button then Sub View 1 has to be unloaded and RootViewController should load the Sub View 2.

Query

I have successfully displayed SubView 1 and when user taps on DONE then I can unload it. But I did n’t get how should I notify the RootViewController from Sub View 1 that Sub View 1 has unloaded and now it should load the Sub View 2?

Thanks in Advance

Paras Mendiratta

  • 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-24T09:39:47+00:00Added an answer on May 24, 2026 at 9:39 am

    Here is my code where I tried to use delegate pattern.

    The problem is the sub view 1 (videoPlayer) is not able to call the delegate methods. 🙁

    ViewSwitcher.h – Root Controller

    @class VideoPlayer; //Sub View 1
    @class LandingPage; //Sub View 2
    
    @protocol viewSwitcherDelegate 
    
    -(void)notifyViewSwitcher;
    
    @end
    
    @interface ViewSwitcher : UIViewController 
    {
       id <viewSwitcherDelegate> delegate;
    }
    
    @property (nonatomic, retain) VideoPlayer *videoPlayer;
    @property (nonatomic, retain) LandingPage *landingPage;
    
    @property(assign) id <viewSwitcherDelegate> delegate;
    
    -(void)loadSecondView;
    -(void)delegateSetInSubView;
    
    @end
    

    ViewSwitcher.m – Implementation

    @synthesize videoPlayer;
    @synthesize landingPage;
    //@synthesize delegate;
    
    // 1.4 -> Declare the delegate constructor
    - (id <viewSwitcherDelegate>)delegate
    {
        return delegate;
    }
    
    // 1.5 -> Declare the setDelegate method
    - (void)setDelegate:(id <viewSwitcherDelegate>)v
    {
        delegate = v;
    }
    - (void)viewDidLoad
    {
        VideoPlayer *videoController = [[VideoPlayer alloc] initWithNibName:@"VideoPlayer" bundle:nil];
        self.videoPlayer = videoController;
        [self.view insertSubview:videoController.view atIndex:0];
        [videoController release];
        [super viewDidLoad];
    }
    
    -(void)loadSecondView
    {
        NSLog(@"Call for loading 2nd View");
    }
    

    VideoPlayer.h – SubView 1 (Movie Player)

    @interface VideoPlayer : UIViewController <viewSwitcherDelegate>
    {
        ViewSwitcher *viewSwitcher;
        MPMoviePlayerController *videoController;
    }
    
    @end
    

    VideoPlayer.m – implementation

    -(void)notifyViewSwitcher
    {
        NSLog(@"notifyViewSwitcher called.");
        //Attempted to call the loadSecondView of ViewSwitcher
    

    I tried calling delegate’s method but in log nothing is printed.

        [viewSwitcher loadSecondView];
    }
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        // Setting the delegate
        viewSwitcher.delegate = self;
        return self;
    }
    
    - (void)viewDidLoad
    {
        NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"bumper.mp4" ofType:nil];
        NSURL *url = [NSURL fileURLWithPath:urlStr];
    
        videoController = [[MPMoviePlayerController alloc] initWithContentURL:url];
        videoController.controlStyle = MPMovieControlStyleNone;
        [self.view addSubview:videoController.view];
    
        videoController.view.frame = CGRectMake(0, 0, 480, 320);
        videoController.fullscreen = YES;
    
        // Remove the status bar from this view.
        [[UIApplication sharedApplication] setStatusBarHidden:YES animated:UIStatusBarAnimationFade];
    
        // TODO: This observer needs to be removed.
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(playbackStateChange:)
                                                     name:MPMoviePlayerPlaybackDidFinishNotification
                                                   object:videoController];
    
        // Play the video.
        [videoController play];
    
        [super viewDidLoad];
    }
    
    // Receives notification once movie is finished.
    -(void)playbackStateChange:(NSNotification*)notification
    {
        // TODO: Switch the view.
    
        NSLog(@"Notification = %@", notification);
        [self notifyViewSwitcher];
    }
    

    Here is the LOG:-

    2011-08-03 02:44:47.333 My Video Player[24016:207] Notification = NSConcreteNotification 0x5768280 {name = MPMoviePlayerPlaybackDidFinishNotification; object = <MPMoviePlayerController: 0x5740940>; userInfo = {
        MPMoviePlayerPlaybackDidFinishReasonUserInfoKey = 0;
    }}
    2011-08-03 02:44:47.337 My Video Player[24016:207] notifyViewSwitcher called.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to iPhone programming. what I am trying is I have one
I'm fairly new to iPhone programming and am trying to implement a double-component PickerView.
I'm new to iPhone programming, and I'm trying to make a simple program without
I am new in iPhone programming. At the moment I am trying to recognize
am new to iphone programming. I have a viewcontoller with an alertview in it.
I am new to iPhone programming. I have 10 number say (1,2,3,4,5,6,7,8,9,10) . I
I'm quite new in iPhone Programming, but I'm trying to do my best cause
I'm very new to iphone programming. I'm trying to write an application where I
I'm new to iPhone programming and I'm trying to use CHDataStructures in my project.
I am new to iPhone programming. I have two textfields in iPhone with numberPad

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.