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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:20:45+00:00 2026-05-14T07:20:45+00:00

I am struggling trying to perform what I would think would be a relatively

  • 0

I am struggling trying to perform what I would think would be a relatively common task. I have an NSTableView that is bound to it’s array via an NSArrayController. The array controller has it’s content set to an NSMutableArray that contains one or more NSObject instances of a model class. What I don’t know how to do is expose the model inside the NSCell subclass in a way that is bindings friendly.

For the purpose of illustration, we’ll say that the object model is a person consisting of a first name, last name, age and gender. Thus the model would appear something like this:

@interface PersonModel : NSObject {
    NSString * firstName;
    NSString * lastName;
    NSString * gender;
    int * age;
}

Obviously the appropriate setters, getters init etc for the class.

In my controller class I define an NSTableView, NSMutableArray and an NSArrayController:

@interface ControllerClass : NSObject {
    IBOutlet NSTableView * myTableView;
    NSMutableArray * myPersonArray;
    IBOutlet NSArrayController * myPersonArrayController;
}

Using Interface Builder I can easily bind the model to the appropriate columns:

myPersonArray --> myPersonArrayController --> table column binding

This works fine. So I remove the extra columns, leaving one column hidden that is bound to the NSArrayController (this creates and keeps the association between each row and the NSArrayController) so that I am down to one visible column in my NSTableView and one hidden column. I create an NSCell subclass and put the appropriate drawing method to create the cell. In my awakeFromNib I establish the custom NSCell subclass:

MyCustomCell * aCustomCell = [[[MyCustomCell alloc] init] autorelease];
[[myTableView tableColumnWithIdentifier:@"customCellColumn"] 
     setDataCell:aCustomCell];

This, too, works fine from a drawing perspective. I get my custom cell showing up in the column and it repeats for every managed object in my array controller. If I add an object or remove an object from the array controller the table updates accordingly.

However… I was under the impression that my PersonModel object would be available from within my NSCell subclass. But I don’t know how to get to it. I don’t want to set each NSCell using setters and getters because then I’m breaking the whole model concept by storing data in the NSCell instead of referencing it from the array controller.

And yes I do need to have a custom NSCell, so having multiple columns is not an option. Where to from here?

In addition to the Google and StackOverflow search, I’ve done the obligatory walk through on Apple’s docs and don’t seem to have found the answer. I have found a lot of references that beat around the bush but nothing involving an NSArrayController. The controller makes life very easy when binding to other elements of the model entity (such as a master/detail scenario). I have also found a lot of references (although no answers) when using Core Data, but Im not using Core Data.

As per the norm, I’m very grateful for any assistance that can be offered!

  • 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-14T07:20:45+00:00Added an answer on May 14, 2026 at 7:20 am

    Finally figured this one out. Man that took some doing. So here is what I needed to do…

    First of all I needed to create an array of my model’s key values in my model object and return those key values in an NSDictionary from within the model.

    Thus my model got two new methods as follows (based on my simplified example above):

    +(NSArray *)personKeys
    {
        static NSArray * personKeys = nil;
        if (personKeys == nil)
            personKeys = [[NSArray alloc] initWithObjects:@"firstName", @"lastName", @"gender", @"age", nil];
    
        return personKeys;
    }
    
    -(NSDictionary *)personDictionary
    {
        return [self dictionaryWithValuesForKeys:[[self class] personKeys]];
    }
    

    Once implemented, I assign my bound value in my table to

    arrayController --> arrangeObjects --> personDictionary.

    The last step is to reference the object in the NSCell drawWithFrame and use as needed as follows:

    NSDictionary * thisCellObject = [self objectValue];
    
    NSString * objectFirstName = [thisCellObject valueForkey:@"firstName"];
    NSString * objectLastName = [thisCellObject valueForKey:@"lastName"];
    

    And as I hoped, any update to the model object reflects in the custom NSCell.

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

Sidebar

Related Questions

I'm struggling with trying to sort an array of dictionaries. My dictionaries have a
I've been struggling with trying to get my commandButtons to perform an action (yet
I have been struggling with trying to send an email with an attachment using
I'm really struggling trying to find something that actually works for getting the basics
I'm struggling trying to make a cron job run. Here is what I have:
I am trying to write a query that would select data from multiple lines
I have been struggling trying to figure out how to conditionally include Flex libraries
(for the D programming language) I've been struggling trying to initialise an associative array
I am really struggling trying to get something very simple achieved. Essentially, I have
I am struggling with an SQL time comparison on two fields that have been

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.