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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:05:07+00:00 2026-06-13T12:05:07+00:00

I have 3 subclasses: a Block class, a Row class and a Table class.

  • 0

I have 3 subclasses: a Block class, a Row class and a Table class. All are subclasses of NSView.
I have a Table added with IB which programmatically displays 8 rows, each of which displays 8 blocks. I overrode the mouseDown: method in Block to change the background color to red, but it doesn’t work. Still if I add a block directly on top of the Table with IB it does work so I can’t understand why it won’t work in the first case.

Here’s the implementation code for Block and Row (Table’s implementation works the same way as Row’s):

//block.m

- (void)drawRect:(NSRect)dirtyRect
{
    [color set];
    [NSBezierPath fillRect:dirtyRect];
}

-(void)mouseDown:(NSEvent *)theEvent
{
    color = [NSColor redColor];
    checked = YES;
    [self setNeedsDisplay:YES];
}

//row.m

- (void)drawRect:(NSRect)dirtyRect
{

    [[NSColor blueColor] set];
    [NSBezierPath fillRect:dirtyRect];
    int x;
    for(x=0; x<8; x++){
    int margin = x*2;
    NSRect rect = NSMakeRect(0, 50*x+margin, 50, 50);
    Block *block = [[Block alloc] initWithFrame:rect];
    [self addSubview:block];
    }
}
  • 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-13T12:05:08+00:00Added an answer on June 13, 2026 at 12:05 pm

    I understood the problem… since the mouseDown implementation would cause the block to redraw, and so even its superview, it would call Table’s drawRect: method causing it to draw new blocks on top of the old ones, and so it would seem never to change color. So I created a property for Table called isFirstAppearance initially set to YES which if YES makes the table draw the rows and sets itself to NO.

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

Sidebar

Related Questions

I have a common base class from which all my ASMX webservice classes will
I have several Activity subclasses in my project, each calling a SOAP based web
I have a Data class that subclasses NSManagedObject with a single bool property attribute.
I have a basic class that derived subclasses inherit from, it carries the basic
I have a super class and two subclasses and I want to serialize the
I have a superclass we can call class A and few subclasses, e.g. class
I have a class Manager and a class Base (with subclasses deriving from Base,
I have a NSManagedObjectContext in which I have a number of subclasses of NSManagedObjects
I have an abstract base class called Party. There are several concrete subclasses (Company,
In C++, I have an Object class, from which a number of other classes

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.