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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:09:43+00:00 2026-05-13T13:09:43+00:00

Hellow stackoverflow people, I am pretty new to Cocoa. I have XCode 3.1 Situation:

  • 0

Hellow stackoverflow people,
I am pretty new to Cocoa. I have XCode 3.1

Situation:
I have a NSObject subclass: (AppController) with an action, linked to a button.
Than i have a custom View, connected to my NSView subclass (AppView), in the drawRect command i draw a rectangle (all that stuff works),
i have in the AppView.m a function – (void) drawIt { .. } which draws the rectangle.
For now i called it in the – (void) drawRect … with [self drawIt]. That works too.

What i want to do now is to call drawIt when the button is clicked. (in the AppController.m when the Action -(IBAction) … is called due to a button Click)

I hope u can help me,
I am new to stackoverflow so i dont know wether i should past all the code here, i can but maybe its easier to read like this

  • 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-13T13:09:44+00:00Added an answer on May 13, 2026 at 1:09 pm

    You should read the Cocoa Drawing Guide conceptual material. Your view is asked to -drawRect: by the system when the system feels it’s necessary. In that regard, your view can be asked to draw itself at any time. Therefore, you have to think of this in terms of “drawing the current state”.

    What you should probably do (in this basic situation) is perhaps give your custom view a boolean property “drawIt” and have your button action toggle this on the view instance. This way if (self.drawIt == YES), you can call your rectangle-drawing code.

    You should always do something to “clear” the view when -drawRect: is called (like fill the whole bounds with white), then only draw the conditional stuff if the condition is met.

    Example:

    - (void)drawRect:(NSRect)aRect
    {
      // Clean up background (we ignore "aRect", drawing entire view at once)
      [[NSColor whiteColor] set];
      NSRectFill([self bounds]);
    
      // Do we want to draw our magic rect?
      if ([self drawMagicRect])
      {
        [[NSColor redColor] set];
        NSRectFill([self magicRect]);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 273k
  • Answers 273k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer So i am not clear how this is done? I… May 13, 2026 at 2:11 pm
  • Editorial Team
    Editorial Team added an answer Afaik it's not possible to prepare multiple statements as one… May 13, 2026 at 2:11 pm
  • Editorial Team
    Editorial Team added an answer You could wrap all your verbatim environments in quote environments:… May 13, 2026 at 2:11 pm

Related Questions

Hello wonderful people of stackoverflow! I have a problem. I am working on an
One thing I've always wanted to do is develop my very own operating system
Hello stackoverflow community ! I am trying to figure out how to architect my
Hello stackoverflow pals.I am a new rails learner. My question is: I am listing
If I type: void doThis(){ System.out.println(Hello Stackoverflow.); } what is the default scope of

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.