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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:24:07+00:00 2026-06-02T01:24:07+00:00

How can I call an NSView that is already initialized with another window? newContentView

  • 0

How can I call an NSView that is already initialized with another window?

newContentView = [[CutoutView alloc]initWithFrame:window.frame]; //make a new CutoutView
    [window setContentView:newContentView]; //set it as the contentview of our window
    [newContentView release];

newContentView is an NSView subclass and it is set as the contentView of my window. In the NSView subclass “CutoutView” I have it drawing a simple rect.

In another NSView subclass I want to be able to tell newContentView or just CutoutView that it needs to be redrawn by [setNeedsDisplay:YES] but the only way i can think of doing this is making another [[CutoutView alloc] init]; and when I do that and call set needs display nothing works. It says that it is doing it however it is not displaying probably due to the fact CutOutView is already initialized. How can I access newContentView or just CutoutView from where it was already initialized so that way it will actually display. Thanks!

  • 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-02T01:24:08+00:00Added an answer on June 2, 2026 at 1:24 am

    So first and foremost, you need to get a reference to the particular instance of the CutoutView you created so you can tell that particular instance to redisplay itself.

    You do this in a couple of ways:

    • If you still have a reference to window, just call [[window contentView] setNeedsDisplay:YES].
    • Make the newContentView a property of a particular class so your other class can just access it… fundamentally you’ll have to understand how classes really work in order to answer your question, because this isn’t a technical problem, it’s a conceptual one.

    So the first problem is that you think your CutoutView represents an object, that, as you put it, “has already been initialized.” This is the wrong way to think about it. CutoutView is a class, not an instance.

    You’ve probably already heard the metaphor about a class and a blueprint, so I’ll use something slightly different. CutoutView is a Toyota Prius – not the car, but the model, with the design blueprints and manufacturing process and everything. There’s thousands of Priuses out on the road, the same way there can be thousands of instances of CutoutView.

    Your question seemed to imply that you thought CutoutView is a car, a physical manifestation of a Prius sitting on a driveway; but it fundamentally isn’t.


    A class is a model, the design/brand of a Toyota Prius, or even the Nimitz class aircraft carrier, which describes a type of ship (of which there are 10). The classes, by themselves, don’t mean much.

    An object, or an instance of a class, is the actual thing your program works with. This is what newContentView in your code is. You just told it, metaphorically: (I hope this makes sense)

    NimitzClassCarrier *USSGeorgeHWBush = [[NimitzClassCarrier constructBoat] prepareForLaunch];
    

    enter image description here

    ^ The USS George H.W. Bush finished ‘alloc‘ing in 2009 and was commissioned, inited, and delivered to the Navy early that year.

    enter image description here

    ^the USS Nimitz is another example of an instance of a Nimitz Class Carrier.

    You’ve created an instance of the CutoutView class so you can actually work with it. You can create multiple instances/objects of the same class; there are 10 Nimitz class carriers, after all.


    Hence,

    You can’t tell the USS George H.W. Bush to launch its planes by calling

    NimitzClassCarrier *aCarrier = [[NimitzCarrierClass construct] prepareForLaunch];
    [aCarrier launchPlanes];
    

    Just think about it. All you’re doing is spending millions building another carrier you know as “aCarrier” (a much less seaworthy name) and telling it to launch its planes.

    Instead, what you want to do is to actually get a reference to the USS George H.W. Bush itself to tell it to launch its planes. So now lets go back to your CutoutView. You made an instance of CutoutView and sent it to your window for display. Then you basically sever the direct radio link between you and that instance by letting go of the reference (because I’m assuming you’re having nothing to do with NewContentView ever again.

    Fortunately, the window still has a direct radio communication link with the instance of CutoutView that you created. Hence, my first suggested option is to call [[window contentView] setNeedsDisplay:YES], which tells your particular instance of NSWindow to get its contentView which happens to be the instance of CutoutView you want to display.

    The number ways you can do what you want to do is, after all, endless. You can keep a direct radio communication link to your aircraft carrier and give that means of communication to the other instance of NSView you want to be able to send the aircraft carrier messages. You can cut off all direct communication with the contentView and let the window handle it all, telling the other instance of NSView to ask the window for a radio line.

    [Btw, how the heck do you communicate with aircraft carriers anyways? I don’t think it’s radio… In Objective-C it’s having a pointer to the carrier/object’s memory address, but boats are another world entirely.]

    Or, if as rdelmar asked in the comment way up there, the instance of NSView you want to be able to communicate with the contentView is actually a subview of the contentView… well, think of it this way. The 15th lifeboat wants to be able to tell the USS George HW Bush to launch its planes. How? [[self parentBoat] launchPlanes]. This translates into [[self superview (a.k.a. parentNSView)] setDisplayNeeded:YES].

    Also see @Dmorneault’s answer about other ways you can establish radio communication with your esteemed aircraft carrier which you just sent into the Bermuda triangle.

    The thing is, building a new contentView/boat doesn’t do the trick, and that’s what you’re trying to do and that’s the problem you’re experiencing.

    I don’t think I explained very well, and apologies if this isn’t new to you, but I thought your question indicated a misunderstanding in how classes work. I also know nothing about aircraft carriers, but that was the first thing I came across on Wikipedia.

    Useful conceptual resources:

    • Oracle/Java conceptual docs
    • Apple Docs
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Multiply users can call store procedure(SP) , that will make some changes to mytable
I understand that I can call ToString().IndexOf(...), but I don't want to create an
(Yes I know I can call Java code from Scala; but that is pointless;
Is there any way that I can call a JavaScript function via css? For
I understand I can call window.print() when the page loads to load the print
we can call the Array method in the top level like this Array(something) that
Is there anyway i can call orderedFiles in my asp xml tags so that
I noticed that you can call Queue.Synchronize to get a thread-safe queue object, but
You can call NSPasteboard like this: [pboard declareTypes:types owner:self]; Which means that the pasteboard
I know that I can call a page method with jquery using the following

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.