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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:02:03+00:00 2026-05-15T02:02:03+00:00

I have an NSTableView that binds via an NSArrayController to an NSMutableArray. What’s in

  • 0

I have an NSTableView that binds via an NSArrayController to an NSMutableArray. What’s in the array are derived classes; the first few columns of the table are bound to properties that exist on the base class. That all works fine.

Where I’m running into problem is a column that should only be populated if the row maps to one specific subclass. The property that column is meant to display only exists in that subclass, since it makes no sense in terms of the base class. The user will know, from the first two columns, why the third column’s cell is populated/editable or not.

The binding on the third column’s value is on arrangedObjects, with a model path of something like “foo.name” where foo is the property on the subclass. However, this doesn’t work, as the other subclasses in the hierarchy are not key-value compliant for foo.

It seems like my only choice is to have foo be a property on the base class so everybody responds to it, but this clutters up the interfaces of the model objects.

Has anyone come up with a clean design for this situation? It can’t be uncommon (I’m a relative newcomer to Cocoa and I’m just learning the ins and outs of bindings.)

  • 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-15T02:02:03+00:00Added an answer on May 15, 2026 at 2:02 am

    One way to solve this is to only use bindings for the first two column where it works. For the remaining columns you implement a NSTableViewDataSource that implements the custom logic needed.

    First create a new class that implements

    -tableView:objectValueForTableColumn:row:
    -tableView:setObjectValue:forTableColumn:row:
    

    (you only need the 2nd if the user is supposed to edit the other columns). Then add an

    IBOutlet NSArrayController *valuesController;
    

    instance variable to that class.

    Inside Interface Builder add a new object of that class (drag a blue “object” cube into the file’s window from the library). Connect your array controller to your new data source. Then connect the data source with the table view to make it the table view’s data source.

    Make sure the columns past the first two are not bound to anything.

    The

    -tableView:objectValueForTableColumn:row:
    

    method will get called for those columns as needed and you can look at the object as needed:

    - (id)tableView:(NSTableView *)aTableView
       objectValueForTableColumn:(NSTableColumn *)aTableColumn
                             row:(NSInteger)rowIndex;
    {
        NSObject *myObject = [[valuesController arrangedObjects] objectAtIndex:rowIndex];
        id columnIdentifier = [aTableColumn identifier];
        if ([columnIdentifier isEqual:@"foo"]) {
            if ([myObject respondsToSelector:@selector(fooValue)]) {
                return [myObject fooValue];
            }
        }
        return nil;
    }
    

    Note how I’m using the columns identifier to see which column is being requested. Set the columns identifier inside Interface Builder.

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

Sidebar

Ask A Question

Stats

  • Questions 401k
  • Answers 401k
  • 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 Here are some various ways to upload photos using the… May 15, 2026 at 4:36 am
  • Editorial Team
    Editorial Team added an answer Not really an answer but I used Pool.imap()instead: for i… May 15, 2026 at 4:36 am
  • Editorial Team
    Editorial Team added an answer That's a package in the Colt library. Once you download… May 15, 2026 at 4:36 am

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.