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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:00:28+00:00 2026-05-16T02:00:28+00:00

I’ve been attempting this for two days, and constantly running into dead ends. I’ve

  • 0

I’ve been attempting this for two days, and constantly running into dead ends.

I’ve been through Aaron Hillegass’s Cocoa Programming for MAC OS X, and done all the relevant exercises dealing with NSTableview and mutable arrays, and I have been attempting to modify them to suit my needs.

However none of them seem to be using an array with objects as a data source, it seems to use the tableview as the datasource.

I’m trying to implement Jonas Jongejan’s "reworking" of my code here, with a Cocoa front end to display the results.

Any pointers or suggestions I know this should be simple, but I’m lost in the wilderness here.

I can populate the table by setting the array

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

    It’s pretty simple really, once you get to understand it (of course!). You can’t use an NSArray directly as a table source. You need to either create a custom object that implements NSTableViewDataSource or implement that protocol in some existing class – usually a controller. If you use Xcode to create a standard document based application, the document controller class – (it will be called MyDocument) is a good class to use.

    You need to implement at least these two methods:

    – numberOfRowsInTableView:
    – tableView:objectValueForTableColumn:row:
    

    If you have a mutable array whose values you’d like to use in a table view with one column, something like the following should do as a start:

    – numberOfRowsInTableView: (NSTableView*) aTableView
    {
        return [myMutableArray count];
    }
    
    – tableView: (NSTableView*) aTableView objectValueForTableColumn: (NSTableColumn *)aTableColum row: (NSInteger)rowIndex
    {
        return [myMutableArray objectAtIndex: rowIndex];
    }
    

    It has just occurred to me that you could add the above two methods as a category to NSArray replacing myMutableArray with self and then you can use an array as a data source.


    Anyway, with a mutable array, it is important that any time you change it, you need to let the table view know it has been changed, so you need to send the table view -reloadData.


    If your table view has more than one column and you want to populate it with properties of objects in your array, there’s a trick you can do to make it easier for yourself. Let’s say the objects in your array are instances of a class called Person with two methods defined:

    -(NSString*) givenName;
    -(NSString*) familyName;
    

    and you want your table view to have a column for each of those, you can set the identifier property of each column to the name of the property in Person that that column displays and use something like the following:

    – tableView: (NSTableView*) aTableView objectValueForTableColumn: (NSTableColumn *)aTableColum row: (NSInteger)rowIndex
    {
        Person* item = [myMutableArray objectAtIndex: rowIndex];
        return [item valueForKey: [tableColumn identifier]];
    }
    

    If you replace valueForKey: with valueForKeyPath: and your Person class also has the following methods:

    -(Person*) mother;
    -(Person*) father;
    -(NSString*) fullName;  // concatenation of given name and family name
    

    you can add table columns with identifiers like: father.fullName or mother.familyName and the values will be automatically populated.

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

Sidebar

Related Questions

No related questions found

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.