• 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: Subclassing NSArrayController arrangeObjects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Subclassing NSArrayController arrangeObjects


  • Subject: Re: Subclassing NSArrayController arrangeObjects
  • From: mmalcolm crawford <email@hidden>
  • Date: Wed, 19 May 2004 23:36:10 -0700

On May 19, 2004, at 1:47 PM, Gabriele de Simone wrote:

I have run into a problem with NSArrayController arrangeObjects. I am attempting to do the converse of filtering, that is: in my subclass' arrangeObjects I *add* objects rather than filter them out, like in the following code:
- (NSArray *)arrangeObjects:(NSArray *)objects {
NSMutableArray* arrangedObjects = [NSMutableArray array];
[arrangedObjects setArray:[super arrangeObjects:objects]];
[arrangedObjects insertObject:myHardCodedFirstElement
atIndex:0];
[arrangedObjects addObject:myHardCodedLastElement];
return arrangedObjects;
}
[...]
Now, the subclass whose code I pasted above is used by an NSTableView. I would assume that the NSTableView should display at least my 2 hardcoded elements even when the "parent" NSArrayController is empty (because I am explicitly adding 2 elements). The fact is, the table view remains empty.
If I then add one element to the "base" NSArrayController, the table will suddendly display all three elements. If I remove any of these elements, it will go back to empty.

If the 'count' of the array you've bound to is 0, it would seem reasonable not to bother arranging the objects, since there aren't any...

I am adding elements to the "base" controller. Adding elements to the next controller up in the chain ("plusTwo") will cause a failure (it probably fails for the same reason insertions fail when filtering, but I don't care about solving that problem here).
I have tried overriding countOfArrangedObjects for the "plusTwo" controller but that doesn't do it. Neither does a reloadData on the table view.

Have you implemented any other of the indexed accessors, like objectInArrangedObjectsAtIndex:?

<http://developer.apple.com/documentation/Cocoa/Conceptual/ KeyValueCoding/Concepts/AccessorConventions.html#//apple_ref/doc/uid/ 20002174/BAJEDEFB>

If you're altering values, it would also seem better to implement and bind to something other than arrangedObjects -- on which other features might depend...

- (unsigned int) countOfFakeArrangedObjects;
- (id) objectInFakeArrangedObjectsAtIndex: (unsigned int)index;

mmalc
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


  • Follow-Ups:
    • Re: Subclassing NSArrayController arrangeObjects
      • From: Gabriele de Simone <email@hidden>
References: 
 >Subclassing NSArrayController arrangeObjects (From: Gabriele de Simone <email@hidden>)

  • Prev by Date: Re: Global preferences using CFPreferences
  • Next by Date: Re: Trap NSLogs
  • Previous by thread: Subclassing NSArrayController arrangeObjects
  • Next by thread: Re: Subclassing NSArrayController arrangeObjects
  • Index(es):
    • Date
    • Thread