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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:08:02+00:00 2026-05-28T22:08:02+00:00

I am currently populating an NSTableView through the controller (MVC design pattern) where I

  • 0

I am currently populating an NSTableView through the controller (MVC design pattern) where I initialise one entry of a NSMutableArray in the controller’s init method.

How would I:

  1. Populate my NSMutableArray which is an array of Person objects
  2. Should I populate the NSMutableArray in my mainViewDidLoad method of my base class instead? I have not found any examples or resources for this.

Model (Person.m)

#import "Person.h"


@implementation Person

@synthesize name;
@synthesize gender;

- (id)init
{
    self = [super init];
    if (self) {
        name = @"Bob";
        gender = @"Unknown";
    }

    return self;
}

- (void)dealloc
{
    self.name = nil;
    self.gender = nil;

    [super dealloc];
}

@end

Controller (PersonController.m)

#import "PersonController.h"
#import "Person.h"


@implementation PersonController

- (id)init
{
    self = [super init];
    if (self) {
        PersonList = [[NSMutableArray alloc] init];
//        [personList addObject:[[Person alloc] init]];
//        
//        [personTable reloadData];
    }

    return self;
}

- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView {
    return [personList count];
}

- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row {
    Person *person = [personList objectAtIndex:row];
    NSString *identifier = [tableColumn identifier];

    return [person valueForKey:identifier];
}

- (void)dealloc
{
    [super dealloc];
}

@end

Base file (Main.h):

#import "Main.h"

@implementation Main

- (void)mainViewDidLoad
{

}

@end
  • 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-28T22:08:02+00:00Added an answer on May 28, 2026 at 10:08 pm

    How would I:

    • Populate my NSMutableArray which is an array of Person objects

    Step 1: Create Person objects.

    Step 2: Add them to the array.

    Your commented-out code does exactly this, although you should probably create the Person separately in case you want to configure it (e.g., set its name).

    Should I populate the NSMutableArray in my mainViewDidLoad method of my base class instead?

    It doesn’t really matter how far in advance of the user seeing your model you create it, but conceptually, it kind of smells to me. It doesn’t have anything to do with the view, so I say it belongs in init.

    Of course, if the main view—and every view in it—has already loaded, you’ll need to tell the table view to reload your data to get it to show any changes you made to the array. Conversely, if you create the model before loading the view, you don’t need to reload initially, because the table view will have already asked you for your model once.

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

Sidebar

Related Questions

I am running JSF 2.0 I currently have one java controller that is called
Using C# / .NET 3.5. Currently I'm populating 2 DataTables one after the other
I am currently building a .Net userform using C# and I am populating it
Currently, I don't really have a good method of debugging JavaScript in Internet Explorer and
I currently have a map mashup that has locations that I'm populating from my
Currently I'm populating my tableviewcells with the contents of multiple arrays representing a name,
I currently have this code for populating a list of comments to return: foreach
I'm currently reading in a list of tables in a SQL database and populating
I have a Grails application that uses ThreadLocal. Currently ThreadLocal populating and clearing is
Let's say I have a handler in a Spring MVC controller: @RequestMapping public String

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.