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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:36:54+00:00 2026-06-04T11:36:54+00:00

I have a view based NSOutlineView which displays entries (Source entity) from a Core

  • 0

I have a view based NSOutlineView which displays entries (Source entity) from a Core Data store. The view in the outline view uses a custom control which is implemented as a subclass of NSView. This control displays a round coloured marker based on a numerical value (0-7). This value is stored as an attribute of the Source entity and is intended as a method to implement a Finder-like method of labeling.

The whole thing is wired using bindings with IB.

I have attached a screenshot which will hopefully make my intentions clear.

It all works good but for one really annoying detail. When the numerical value is changed (from the right side of the screen) the custom control is only updated when the selection in the outline view is changed. Obviously it would be nicer to have this change reflected immediately but I’ve failed so far. I’ve tried various scenario’s with setNeedsDisplay: YES which were all basically ignored.

Any ideas?

enter image description here

Edit: I implemented a setter with the custom control:

- (void) setLabelValue: (NSNumber*) aValue {
    labelValue = aValue;
    [self setNeedsDisplay: YES];
}

Reasoning that the setNeedsDisplay: would trigger a re-draw, in the drawRect: method I query the value to establish the proper color:

- (void)drawRect: (NSRect) dirtyRect {
    // Label value between '1' and '7' indicate that a label was assigned. Determine label color and border color.
    if ([[self labelValue] intValue] > 0) {
        NSColor *aBackgroundColor = [NSColor clearColor];
        switch ([[self labelValue] intValue]) {
            case 1:
                aBackgroundColor = [NSColor colorWithCalibratedRed:...];
                break;
            case 2:
                aBackgroundColor = [NSColor colorWithCalibratedRed:...];        
                break;
            case 3:
                aBackgroundColor = [NSColor colorWithCalibratedRed:...];
                break;
            case 4:
                aBackgroundColor = [NSColor colorWithCalibratedRed:...];    
                break;
            case 5:
                aBackgroundColor = [NSColor colorWithCalibratedRed:...];        
                break;
            case 6:
                aBackgroundColor = [NSColor colorWithCalibratedRed:...];            
                break;
            case 7:
                aBackgroundColor = [NSColor colorWithCalibratedRed:...];        
                break;
        }
        // Draw border first.
        ...
        // Draw label color.
        ...
    } 
    // Label value of '0' indicates that no label was assigned.
    if ([[self labelValue] intValue] == 0) {
        NSBezierPath *aPath = [NSBezierPath bezierPathWithRoundedRect: ...];
        [[NSColor clearColor] set];
        [aPath fill];
    }
}
  • 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-04T11:36:56+00:00Added an answer on June 4, 2026 at 11:36 am

    I reimplemented the whole thing using notifications. I could not get it to work using bindings. Here’s what I did:

    The controller of the NSOutlineView (left part of the screen) distributes views for its elements using the method:

    - (NSView *) outlineView: (NSOutlineView *) outlineView viewForTableColumn: (NSTableColumn *) tableColumn item: (id) anItem
    

    When an entity associated to a file (an image, PDF etc) is added to the outline view, the item view (custom subclass of NSTableCellView) for that particular item registers an interest in changes to the labelValue property of the entity:

    [[NSNotificationCenter defaultCenter] addObserver: aView selector: @selector(labelValueChanged:) name: @"LabelValueChanged" object: nil];
    

    When a change in the labelValue property occurs (through a click on one of the buttons in the right part of the screen), that controller fires a notification:

    [[NSNotificationCenter defaultCenter] postNotificationName:@"LabelValueChanged" object:[self selectedSource]];
    

    Throught the Notification system, the method labelValueChanged: gets called by the item view (in the NSOutlineView) which invalidates the display of the custom view components that actually draws the label:

    - (void) labelValueChanged: (NSNotification*) aNotification {
        // A notification was received that the label was changed. Mark the label object of the receiver
        // if the object in the notification (anObject) matches the object of the receiver (objectValue).
        id anObject = [aNotification object];
        if (anObject == [self objectValue]) {
            [[self label] setNeedsDisplay:YES];
        }
    }
    

    Thanks to @KenThomases for his suggestions.

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

Sidebar

Related Questions

Say I have a template which displays a view based on a property: {{#if
I have an iPhone app which has a Table View-based data input screen with
I have a controller which displays a list of CourseID in a view based
I have an view in my App which has a number of buttons based
I have just added a Core Plot view to my application based on a
I have a View-based NSOutlineView bound to a NSTreeController. Everything seems to work correctly
I have a view-based NSTableView populated custom NSTabelCellView subclass, which are the lowest objects
I have a view-based application and I'd like to make a change to which
I have a non document-based Core Data application. There's an NSTreeController that manages a
I have implemented a view-based NSOutlineView in my project. I am using floating group

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.