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

  • Home
  • SEARCH
  • 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 3431078
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:16:55+00:00 2026-05-18T07:16:55+00:00

I have a View Controller that initializes a UIView as its view. That view

  • 0

I have a View Controller that initializes a UIView as its view. That view initializes another UIView as a subview. Both UIViews communicate with the View Controller through a delegate/protocol.

Each UIView creates an instance of the ViewController and makes it equal to the delegate:

ViewController *aDelegate = [[ViewController alloc] init];
self.delegate = aDelegate;

PROBLEM: The View Controller has a variable called (int)selection that is modified by both UIViews. Both views must know how each other modified the variable, but since each has a different instance of the View Controller that communication is impossible. How would I fix this problem?

Thanks a ton

EDIT: Peter mentioned assigning the delegate at the views creation which I like, but how would I do that for the subview since it is created in the UIView and not the View Controller. PS. In reality it is a subview of a subview of a subview so can I create them all in the View Controller and then assign it as the delegate?

Tried assigning the delegate as follows but it continually crashes when I attempt to call a ViewController method from the view:

MyView *mainView = [[MyView alloc] initWithFrame:frame];
self.view = mainView;
mainView.delegate = self;
[mainView release];
  • 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-18T07:16:56+00:00Added an answer on May 18, 2026 at 7:16 am

    The views does not need to know about each other. In your view controller you define a property for the sub view

    @property (nonatomic, retain) MyView *myView;

    Then you create your sub view and assign the delegate. This can be done in viewDidLoad

    - (void)viewDidLoad {
        [super viewDidLoad];
    
        CGRect frame = ...;
        MyView *subView = [[MyView alloc] initWithFrame:frame];
        self.myView = subView;
        subView.delegate = self;
        [self.view addSubView:subView];
        [subView release];
    
    
        self.view.delegate = self;
    } 
    

    Then in your delegate method, which I just guessed how it could look, you can update the view controller as well as the other view.

    - (void)view:(MyView *)view didUpdateSelection:(int)newSelection {
        self.selection = newSelection;
        if (view == self.view) {
            self.myView.selection = newSelection;
        }
        else {
            self.view.selection = newSelection;
        }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a viewController (Planner) that loads two view controllers (InfoEditor and MonthlyPlan) when
Lets say I have a view, myView, a view controller, myViewController, and some sort
A simple question: I have a Model-View-Controller setup, with Models accessing a SQL database.
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
When submitting one form from view, how can i also read or have controller
I have a view that has a list of jobs in it, with data
I have a view using a master page that contains some javascript that needs
I have a view user control that can post form. This control can be
We have a View (call it X) that is the base view called by
I have a view that I want to add some custom drawing to. I

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.