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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:15:37+00:00 2026-05-30T15:15:37+00:00

I’d like my controller to subscribe to notifications from view. However, before doing that,

  • 0

I’d like my controller to subscribe to notifications from view. However, before doing that, I’d like to confirm if it is OK for a view to know the instance of its controller?

Let me offer you a more specific example of what I have in mind.

My controller creates the view and informs it that it is its controller

self.gameView = [[GameView alloc] initWithController:self];

Once done, it subscribes for notifications from this view

[[NSNotificationCenter defaultCenter] addObserver:self 
                                   selector:@selector(saySomething:)
                                   name:@"SaySomethingClever" object:nil];

Meanwhile the view does its thing, but when the right time comes, it posts a notification

[[NSNotificationCenter defaultCenter] postNotificationName:
                                        @"SaySomethingClever" object:gvc];

In order for it to do it, the view needs to know the recipient of the notification (gvc).

I’d like to use this opportunity and as you whether the following is ok:

When initWithController is called, the view

-(id) initWithController: (GameViewController* )g {
    gvc = g;
    return [self initWithFrame:CGRectMake(0, 0, 480, 300)];
}

where initWithFrame:CGRectMake is a private method that handles specific view stuff.

Everything works fine, however, i wonder whether this approach is morally acceptable

  • 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-30T15:15:38+00:00Added an answer on May 30, 2026 at 3:15 pm

    It’s not strictly a problem if the view has a reference to its controller, but it looks like your real problem is a misunderstanding of the notification posting method.

    The object argument isn’t the receiver. Indeed, if it were — if the poster of a notification had to know the object that was going to get the notification — that would defeat the entire purpose of the notification. You could just call the appropriate method! The point of notifications is that the poster doesn’t need to know the other objects which are listening.

    The object argument is actually used by the receiver to distinguish which notifications it should care about. Most frequently, the argument is the poster itself:

    [[NSNotificationCenter defaultCenter] postNotificationName:IDidSomethingInteresting
                                                        object:self];
    

    but it can in fact be any object.

    When registering for notifications, you can specify a particular instance whose notifications you’re interested in. This is the object argument to addObserver:... The notification center will then only pass on those notifications whose name and object match what was specified.

    Even if you pass nil for the object in addObserver:..., you can check the object of a received notification and only act if the poster was one that you are interested in.

    For example, there might be several windows in you application, and you may be interested in knowing when one of them is resized, but you don’t care what happens to the rest of them. You would pass just that window instance as the object for addObserver:...

    To sum up, your view in this case doesn’t need that reference to its controller in order to for the controller to receive notifications posted by the view.

    See also: “Posting Notifications”

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from

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.