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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:55:16+00:00 2026-05-13T12:55:16+00:00

What do I need to do to update a tableView bound to an NSArrayController

  • 0

What do I need to do to update a tableView bound to an NSArrayController when a method is called that updates the underlying array? An example might clarify this.

When my application launches, it creates a SubwayTrain. When SubwayTrain is initialised, it creates a single SubwayCar. SubwayCar has a mutable array ‘passengers’. When a Subway car is initialised, the passengers array is created, and a couple of People objects are put in (let’s say a person with name “ticket collector” and another, named “homeless guy”). These guys are always on the SubwayCar so I create them at initialisation and add them to the passengers array.

During the life of the application people board the car. ‘addPassenger’ is called on the SubwayCar, with the person passed in as an argument.

I have an NSArrayController bound to subwayTrain.subwayCar.passengers, and at launch my ticket collector and homeless guy show up fine. But when I use [subwayCar addPassenger:], the tableView doesn’t update. I have confirmed that the passenger is definitely added to the array, but nothing gets updated in the gui.

What am I likely to be doing wrong? My instinct is that it’s KVO related – the array controller doesn’t know to update when addPassenger is called (even though addPassenger calls [passengers addObject:]. What could I be getting wrong here – I can post code if it helps.

Thanks to anyone willing to help out.

UPDATE

So, it turns out I can get this to work by changing by addPassenger method from

[seatedPlayers addObject:person];

to

NSMutableSet *newSeatedPlayers = [NSMutableSet setWithSet:seatedPlayers];

[newSeatedPlayers addObject:sp];

[seatedPlayers release];

[self setSeatedPlayers:newSeatedPlayers];

I guess this is because I am using [self setSeatedPlayers]. Is this the right way to do it? It seems awfully cumbersome to copy the array, release the old one, and update the copy (as opposed to just adding to the existing 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-13T12:55:17+00:00Added an answer on May 13, 2026 at 12:55 pm

    So, it turns out I can get this to work by changing by addPassenger method from

    [seatedPlayers addObject:person];
    

    to

    NSMutableSet *newSeatedPlayers = [NSMutableSet setWithSet:seatedPlayers];
    [newSeatedPlayers addObject:sp];
    [seatedPlayers release];
    [self setSeatedPlayers:newSeatedPlayers];
    

    I guess this is because I am using [self setSeatedPlayers]. Is this the right way to do it?

    First off, it’s setSeatedPlayers:, with the colon. That’s vitally important in Objective-C.

    Using your own setters is the correct way to do it, but you’re using the incorrect correct way. It works, but you’re still writing more code than you need to.

    What you should do is implement set accessors, such as addSeatedPlayersObject:. Then, send yourself that message. This makes adding people a short one-liner:

    [self addSeatedPlayersObject:person];
    

    And as long as you follow the KVC-compliant accessor formats, you will get KVO notifications for free, just as you do with setSeatedPlayers:.

    The advantages of this over setSeatedPlayers: are:

    • Your code to mutate the set will be shorter.
    • Because it’s shorter, it will be cleaner.
    • Using specific set-mutation accessors provides the possibility of specific set-mutation KVO notifications, instead of general the-whole-dang-set-changed notifications.

    I also prefer this solution over mutableSetValueForKey:, both for brevity and because it’s so easy to misspell the key in that string literal. (Uli Kusterer has a macro to cause a warning when that happens, which is useful when you really do need to talk to KVC or KVO itself.)

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

Sidebar

Ask A Question

Stats

  • Questions 426k
  • Answers 426k
  • 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 You can use appache Validator Commons .. UrlValidator urlValidator =… May 15, 2026 at 12:31 pm
  • Editorial Team
    Editorial Team added an answer Just because a web crawler is complex in implementation, doesn't… May 15, 2026 at 12:31 pm
  • Editorial Team
    Editorial Team added an answer feedparser 4.1 as available from PyPi has this bug. the… May 15, 2026 at 12:31 pm

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.