• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: programatically updating UI for NSArrayContoller/NSTableView combo
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: programatically updating UI for NSArrayContoller/NSTableView combo


  • Subject: Re: programatically updating UI for NSArrayContoller/NSTableView combo
  • From: Quincey Morris <email@hidden>
  • Date: Sat, 9 Jan 2010 03:29:34 -0800

On Jan 9, 2010, at 00:19, Russell Gray wrote:

> OK, so i checked out the link, and tried the following calls:
>
> [subscriptions insertObject:subscriptionInfo atIndex:[subscriptions count]];
>
> that didn't work, so I tried the following:
>
> [subscriptionsArrayController willChangeValueForKey:@"subscriptions"];
> [subscriptions insertObject:subscriptionInfo atIndex:[subscriptions count]];
> [subscriptionsArrayController didChangeValueForKey:@"subscriptions"];
>
> still, no good, so I also tried:
>
> [subscriptionsArrayController willChangeValueForKey:@"arrangedObjects"];
> [subscriptions insertObject:subscriptionInfo atIndex:[subscriptions count]];
> [subscriptionsArrayController didChangeValueForKey:@"arrangedObjects"];
>
> Am I totally missing something here?

Well, flailing, anyway.

These code samples imply, but don't say, that 'subscriptions' is a NSMutableArray instance variable in some data model object, and that 'subscriptionsArrayController' is a NSArrayController whose "contentArray" is bound to the "subscriptions" property in that data model object, which is backed by the 'subscriptions' instance variable. (It would have been nice if you had given us that information.) Assuming that ...

The problem in the first case is that property "subscriptions" is not being updated KVO-compliantly.

The problem in the second case is that property "subscriptions" is not being updated KVO-compliantly, and array controllers don't have a "subscriptions" property.

The problem in the third case is that property "subscriptions" is not being updated KVO-compliantly, and forcing a KVO notification of the array controller's "arrangedObjects" property doesn't help, because property "subscriptions" is not being updated KVO-compliantly.

Are you seeing a pattern here?

There are two ways you can update the "subscriptions" property KVO-compliantly:

1. [[self mutableArrayValueForKey: @"subscriptions"] insertObject: subscriptionInfo atIndex: [subscriptions count]];

2. [subscriptionsArrayController insertObject: subscriptionInfo atArrangedObjectIndex: [[subscriptionsArrayController arrangedObjects] count]];

These can be abbreviated to:

1. [[self mutableArrayValueForKey: @"subscriptions"] addObject: subscriptionInfo];

2. [subscriptionsArrayController addObject: subscriptionInfo];

In the first case, you add the object via a mutable array proxy that provides KVO compliance, and the array controller will notice accordingly. In the second case, you add the object via the array controller, and it updates your data model property KVO compliantly for you.

Note that you should really define a "subscriptions" property (using @property/@synthesize), if you haven't already. However, it happens to work without the defined property, because KVO looks for a same-named instance variable if the property is missing.

Does that help?


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: programatically updating UI for NSArrayContoller/NSTableView combo
      • From: Russell Gray <email@hidden>
References: 
 >programatically updating UI for NSArrayContoller/NSTableView combo (From: Russell Gray <email@hidden>)
 >Re: programatically updating UI for NSArrayContoller/NSTableView combo (From: mmalc Crawford <email@hidden>)
 >Re: programatically updating UI for NSArrayContoller/NSTableView combo (From: Russell Gray <email@hidden>)

  • Prev by Date: Re: programatically updating UI for NSArrayContoller/NSTableView combo
  • Next by Date: Re: NSDatePicker 24 hour clock
  • Previous by thread: Re: programatically updating UI for NSArrayContoller/NSTableView combo
  • Next by thread: Re: programatically updating UI for NSArrayContoller/NSTableView combo
  • Index(es):
    • Date
    • Thread