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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:15:09+00:00 2026-06-04T21:15:09+00:00

I have a container view controller with 3 child UIViewController subclasses (added with addChildViewController).

  • 0

I have a container view controller with 3 child UIViewController subclasses (added with addChildViewController). I want one of my child view controllers to do something when something is dropped from my container view controller onto it. I’m having trouble grasping how this communication should happen. If I try making a delegate, I get an error in my child view controller because I would both subclasses to import each other.

  • 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-06-04T21:15:10+00:00Added an answer on June 4, 2026 at 9:15 pm

    It sounds like you’re having a problem compiling your app because of mutual .h files importing each other, right?

    Edit: upon reading your question again, I’m not 100% clear on which view controller needs to call which other one. If I mixed up the
    roles of parent and child view controller in my solution, just switch
    them. The techniques below let you communicate between any two view
    controllers (parent and child, sibling and sibling, etc.)

    There’s a number of ways to handle this. If you want to stay with a delegate pattern, you could simply rewrite the header to avoid the #import in one of the .h files:

    ParentViewController.h:

    #import "ChildViewController.h"
    
    @interface ParentViewController: UIViewController {
    @private
       ChildViewController* childVc;
    }
    
    - (void) doSomething;
    

    ChildViewController.h

    @class ParentViewController;   // NOT #import!
    
    @interface ChildViewController: UIViewController {
    @private
       ParentViewController* parentVc;
    }
    

    ChildViewController.m

    #import "ParentViewController.h"
    

    This should avoid the circular dependency that keeps your app from compiling.

    Now, although the above works, I might choose another solution, for the sake of cleanliness. Use a protocol. The parent can implement the protocol and then the child only needs to have a delegate that implements the protocol:

    #import "MyProtocol.h"
    
    @interface ParentViewController: UIViewController<MyProtocol> {
    
    }
    
    - (void) doSomething;
    

    In MyProtocol.h:

    @protocol MyProtocol
     - (void) doSomething;
    @end
    

    Then in ChildViewController.h

    #import "MyProtocol.h"
    
    @interface ChildViewController: UIViewController {
    @private
       id<MyProtocol> delegate;
    }
    
    @property (nonatomic, assign) id<MyProtocol> delegate;
    

    And in ChildViewController.m:

       [delegate doSomething];
    

    Or, you could avoid using delegates altogether, and communicate between the controllers using NSNotificationCenter, which decouples them a bit, and avoids your compiler circularity (bidirectional dependency).

    Here are the Apple docs on NSNotificationCenter

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a container view controller say ContainerViewController and another UIViewController(PhotoViewcController) which i am
I have the following situation: From within a view controller, I go about creating
I have an abstract base Controller class and all action controllers are derived from
I have created a Base-Controller from which all the controllers inherit. Currently this controller
I have a container view controller, that adds 3 set view controller's views to
I have a controller that opens a container view. The container then hands the
I have Navigation View controller that contains web view. The top bar of Navigation
i have view controller which contains a button which show the image library ,if
I have an app with a custom UITabBarController that contains five view controllers. Within
I have a normal UINavigationController with a UIViewController contained in it, when my view

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.