Inherits from | |
Conforms to | |
Framework | /System/Library/Frameworks/AppKit.framework |
Availability | Available in Mac OS X v10.3 and later. |
Declared in | NSArrayController.h |
Companion guides | |
Related sample code |
NSArrayController
is a bindings compatible class that manages a collection of objects. Typically the collection is an array, however, if the controller manages a relationship of a managed object (see NSManagedObject
) the collection may be a set. NSArrayController
provides selection management and sorting capabilities.
– setAvoidsEmptySelection:
– avoidsEmptySelection
– setClearsFilterPredicateOnInsertion:
– preservesSelection
– setPreservesSelection:
– alwaysUsesMultipleValuesMarker
– setAlwaysUsesMultipleValuesMarker:
– selectionIndex
– setSelectionIndex:
– setSelectsInsertedObjects:
– selectsInsertedObjects
– setSelectionIndexes:
– selectionIndexes
– addSelectionIndexes:
– removeSelectionIndexes:
– setSelectedObjects:
– selectedObjects
– addSelectedObjects:
– removeSelectedObjects:
– selectNext:
– canSelectNext
– selectPrevious:
– canSelectPrevious
– addObject:
– addObjects:
– insertObject:atArrangedObjectIndex:
– insertObjects:atArrangedObjectIndexes:
– removeObjectAtArrangedObjectIndex:
– removeObjectsAtArrangedObjectIndexes:
– remove:
– removeObject:
– removeObjects:
– setAutomaticallyRearrangesObjects:
– automaticallyRearrangesObjects
– automaticRearrangementKeyPaths
– didChangeArrangementCriteria
Creates and adds a new object to the receiver’s content and arranged objects.
- (void)add:(id)sender
Typically the object that invoked this method.
Beginning with Mac OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.
NSArrayController.h
Adds object to the receiver’s content collection and the arranged objects array.
- (void)addObject:(id)object
NSArrayController.h
Adds objects to the receiver’s content collection.
- (void)addObjects:(NSArray *)objects
If selectsInsertedObjects
returns YES
(the default), the added objects are selected in the array controller.
It is important to note that inserting many objects with selectsInsertedObjects
on can cause a significant performance penalty. In this case it is more efficient to use the setContent:
method to set the array, or to set selectsInsertedObjects
to NO
before adding the objects with addObjects:
.
NSArrayController.h
Adds objects from the receiver’s content array to the current selection, returning YES
if the selection was changed.
- (BOOL)addSelectedObjects:(NSArray *)objects
Attempting to change the selection may cause a commitEditing
message which fails, thus denying the selection change.
NSArrayController.h
Adds the objects at the specified indexes in the receiver’s content array to the current selection, returning YES
if the selection was changed.
- (BOOL)addSelectionIndexes:(NSIndexSet *)indexes
Attempting to change the selection may cause a commitEditing
message which fails, thus denying the selection change.
NSArrayController.h
Returns a Boolean value that indicates whether the receiver always returns the multiple values marker when multiple objects are selected.
- (BOOL)alwaysUsesMultipleValuesMarker
YES
if the receiver always returns the multiple values marker when multiple objects are selected—even if the selected items have the same value, otherwise NO
.
The default is NO
.
This property is observable using key-value observing.
NSArrayController.h
Returns an array containing the receiver’s content objects arranged using arrangeObjects:
.
- (id)arrangedObjects
An array containing the receiver’s content objects arranged using arrangeObjects:
.
This property is observable using key-value observing.
NSArrayController.h
Returns a given array, appropriately sorted and filtered.
- (NSArray *)arrangeObjects:(NSArray *)objects
An array containing objects filtered using the receiver's filter predicate (see filterPredicate) and sorted according to the receiver’s sortDescriptors
.
Subclasses should override this method to use a different sort mechanism, provide custom object arrangement, or (typically only prior to Mac OS X version 10.4, which provides a filter predicate) filter the objects.
NSArrayController.h
Returns a Boolean value that indicates whether the receiver automatically prepares its content when it is loaded from a nib.
- (BOOL)automaticallyPreparesContent
YES
if the receiver automatically prepares its content when loaded from a nib, otherwise NO
.
See setAutomaticallyPreparesContent:
for a full explanation of "automatically prepares content."
The default is YES
.
Returns a Boolean that indicates if the receiver automatically rearranges its content to correspond to the current sort descriptors and filter predicates.
- (BOOL)automaticallyRearrangesObjects
YES
if the receiver automatically rearranges objects upon changes to the content, NO
if the content does not automatically rearrange.
NSArrayController.h
Returns an array of key paths that trigger automatic content sorting or filtering.
- (NSArray *)automaticRearrangementKeyPaths
An array of key paths that trigger automatic content sorting or filtering.
Subclasses can override this method to customize the default behavior of the sort descriptors and filtering predicates, for example, if additional arrangement criteria are used in custom implementations of rearrangeObjects
.
NSArrayController.h
Returns a Boolean value that indicates whether if the receiver requires that the content array attempt to maintain a selection.
- (BOOL)avoidsEmptySelection
YES
if the receiver requires that the content array attempt to maintain a selection at all times, otherwise NO
.
The default is YES
.
This property is observable using key-value observing.
NSArrayController.h
Returns a Boolean value that indicates whether an object can be inserted into the receiver’s content collection.
- (BOOL)canInsert
YES
if an object can be inserted into the receiver’s content collection, otherwise NO
.
The result of this method can be used by a binding to enable user interface items.
This property is observable using key-value observing.
NSArrayController.h
Returns YES
if the next object, relative to the current selection, in the receiver’s content array can be selected.
- (BOOL)canSelectNext
The result of this method can be used by a binding to enable user interface items.
This property is observable using key-value observing.
NSArrayController.h
Returns YES
if the previous object, relative to the current selection, in the receiver’s content array can be selected.
- (BOOL)canSelectPrevious
The result of this method can be used by a binding to enable user interface items.
This property is observable using key-value observing.
NSArrayController.h
Returns a Boolean value that indicates whether the receiver automatically clears an existing filter predicate when new items are inserted or added to the content.
- (BOOL)clearsFilterPredicateOnInsertion
YES
if the receiver automatically clears an existing filter predicate when new items are inserted or added to the content, otherwise NO
.
The default is YES
.
This property is observable using key-value observing.
NSArrayController.h
Invoked to inform the controller that the arrangement criteria has changed..
- (void)didChangeArrangementCriteria
This is invoked automatically when sort descriptors and filter predicates are changed.
Subclasses should invoke this method when the array returned by automaticallyRearrangesObjects
is changed.
NSArrayController.h
Returns the predicate used by the receiver to filter the array controller contents.
- (NSPredicate *)filterPredicate
The predicate used by the receiver to filter the array controller contents. Returns nil
if no filter predicate is set.
This property is observable using key-value observing.
NSArrayController.h
Creates a new object and inserts it into the receiver’s content array.
- (void)insert:(id)sender
Typically the object that invoked this method.
Beginning with Mac OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.
If an entity name is specified (see entityName
), this method creates an instance of the of the class specified by the entity, otherwise this method creates an instance of the class specified by objectClass
.
NSArrayController.h
Inserts object into the receiver’s arranged objects array at the location specified by index, and adds it to the receiver’s content collection.
- (void)insertObject:(id)object atArrangedObjectIndex:(NSUInteger)index
Subclasses can override this method to provide customized arranged objects support.
NSArrayController.h
Inserts objects into the receiver’s arranged objects array at the locations specified in indexes, and adds it to the receiver’s content collection.
- (void)insertObjects:(NSArray *)objects atArrangedObjectIndexes:(NSIndexSet *)indexes
NSArrayController.h
Returns a Boolean value that indicates whether the receiver will attempt to preserve the current selection then when the content changes.
- (BOOL)preservesSelection
YES
if the receiver attempts to preserve the current selection then when the content changes, otherwise NO
.
The default is YES
.
This property is observable using key-value observing.
NSArrayController.h
Triggers filtering of the receiver’s content.
- (void)rearrangeObjects
This method invokes arrangeObjects:
.
When you detect that filtering criteria change (such as when listening to the text sent by an NSSearchField
instance), invoke this method on self
.
NSArrayController.h
Removes the receiver’s selected objects from the content collection.
- (void)remove:(id)sender
Typically the object that invoked this method.
Beginning with Mac OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.
See removeObject: for a discussion of the semantics of removing objects when using Core Data.
NSArrayController.h
Removes object from the receiver’s content collection.
- (void)removeObject:(id)object
If you are using Core Data, the exact semantics of this method differ depending on the settings for the array controller. If the receiver’s content is fetched automatically, removed objects are marked for deletion by the managed object context (and hence removal from the object graph). If, however, the receiver’s contentSet
is bound to a relationship, removeObject:
by default only removes the object from the relationship (not from the object graph). You can, though, set the “Deletes Object on Remove” option for the contentSet
binding, in which case objects are marked for deletion as well as being removed from the relationship.
NSArrayController.h
Removes the object at the specified index in the receiver’s arranged objects from the receiver’s content array.
- (void)removeObjectAtArrangedObjectIndex:(NSUInteger)index
See removeObject: for a discussion of the semantics of removing objects when using Core Data.
NSArrayController.h
Removes objects from the receiver’s content collection.
- (void)removeObjects:(NSArray *)objects
See removeObject: for a discussion of the semantics of removing objects when using Core Data.
NSArrayController.h
Removes the objects at the specified indexes in the receiver’s arranged objects from the content array.
- (void)removeObjectsAtArrangedObjectIndexes:(NSIndexSet *)indexes
See removeObject: for a discussion of the semantics of removing objects when using Core Data.
NSArrayController.h
Removes objects from the receiver’s current selection, returning YES
if the selection was changed.
- (BOOL)removeSelectedObjects:(NSArray *)objects
Attempting to change the selection may cause a commitEditing
message which fails, thus denying the selection change.
NSArrayController.h
Removes the object as the specified indexes from the receiver’s current selection, returning YES
if the selection was changed.
- (BOOL)removeSelectionIndexes:(NSIndexSet *)indexes
Attempting to change the selection may cause a commitEditing
message which fails, thus denying the selection change.
NSArrayController.h
Returns an array containing the receiver’s selected objects.
- (NSArray *)selectedObjects
This property is observable using key-value observing.
NSArrayController.h
Returns the index of the first object in the receiver’s selection.
- (NSUInteger)selectionIndex
The index of the first object in the receiver’s selection, or NSNotFound
if there is no selection.
This property is observable using key-value observing.
NSArrayController.h
Returns an index set containing the indexes of the receiver’s currently selected objects in the content array.
- (NSIndexSet *)selectionIndexes
An index set containing the indexes of the receiver’s currently selected objects in the content array.
This property is observable using key-value observing.
NSArrayController.h
Selects the next object, relative to the current selection, in the receiver’s arranged content.
- (void)selectNext:(id)sender
The sender is typically the object that invoked this method.
Beginning with Mac OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.
NSArrayController.h
Selects the previous object, relative to the current selection, in the receiver’s arranged content.
- (void)selectPrevious:(id)sender
The sender is typically the object that invoked this method.
Beginning with Mac OS X v10.4 the result of this method is deferred until the next iteration of the runloop so that the error presentation mechanism can provide feedback as a sheet.
NSArrayController.h
Returns whether the receiver automatically selects inserted objects.
- (BOOL)selectsInsertedObjects
YES
if the receiver automatically selects inserted objects, otherwise NO
.
The default is YES
.
This property is observable using key-value observing.
NSArrayController.h
Sets whether the receiver always returns the multiple values marker when multiple objects are selected.
- (void)setAlwaysUsesMultipleValuesMarker:(BOOL)flag
If YES
, the receiver always returns the multiple values marker when multiple objects are selected, even if they have the same value.
Setting flag to YES
can increase performance if your application doesn’t allow editing multiple values. The default is NO.
NSArrayController.h
Sets whether the receiver automatically creates and inserts new content objects automatically.
- (void)setAutomaticallyPreparesContent:(BOOL)flag
If YES
, the receiver automatically prepares its content.
If flag is YES
and the receiver is not using a managed object context, prepareContent
is used to create the content object.
If flag is YES
and a managed object context is set, the initial content is fetched from the managed object context using the current fetch predicate. The controller also registers as an observer of its managed object context. It then tracks insertions and deletions of its entity using the context's notifications, and updates its content array as appropriate.
Setting flag to YES
is the same as checking the “Automatically Prepares Content” option in the Interface Builder controller inspector.
Sets whether or not the receiver automatically rearranges its content to correspond to the current sort descriptors and filter predicates.
- (void)setAutomaticallyRearrangesObjects:(BOOL)flag
A Boolean value that indicates whether the receiver automatically rearranges its content (YES) or not (NO).
The default is NO
.
NSArrayController.h
Sets whether the receiver attempts to avoid an empty selection.
- (void)setAvoidsEmptySelection:(BOOL)flag
If YES
, the receiver maintains a selection unless there are no objects in the content array.
The default is YES
.
NSArrayController.h
Sets whether the receiver automatically clears an existing filter predicate when a new object is inserted or added to the content array.
- (void)setClearsFilterPredicateOnInsertion:(BOOL)flag
If YES
, the receiver automatically clears an existing filter predicate when a new object is inserted or added to the content array.
The default is YES
.
NSArrayController.h
Sets the predicate used to filter the contents of the receiver.
- (void)setFilterPredicate:(NSPredicate *)filterPredicate
The predicate used to filter the contents of the receiver.
If filterPredicate is nil
, any existing filter predicate is removed.
NSArrayController.h
Sets whether the receiver attempts to preserve selection when the content changes.
- (void)setPreservesSelection:(BOOL)flag
If YES
, the receiver attempts to preserve selection when the content changes.
The default is YES
.
NSArrayController.h
Sets objects as the receiver’s current selection, returning YES
if the selection was changed.
- (BOOL)setSelectedObjects:(NSArray *)objects
Attempting to change the selection may cause a commitEditing
message which fails, thus denying the selection change.
NSArrayController.h
Sets the receiver’s selection to the given index, and returns a Boolean value that indicates whether the selection was changed.
- (BOOL)setSelectionIndex:(NSUInteger)index
The index for the selection.
YES
if the selection was changed, otherwise NO
.
Attempting to change the selection may cause a commitEditing
message which fails, thus denying the selection change.
NSArrayController.h
Sets the receiver’s selection indexes and returns a Boolean value that indicates whether the selection changed.
- (BOOL)setSelectionIndexes:(NSIndexSet *)indexes
The set of selection indexes for the receiver.
YES
if the selection was changed, otherwise NO
.
Attempting to change the selection may cause a commitEditing
message which fails, thus denying the selection change.
To select all the receiver’s objects, indexes should be an index set with indexes [0...count -1]
. To deselect all indexes, pass an empty index set.
NSArrayController.h
Sets whether the receiver will automatically select objects as they are inserted.
- (void)setSelectsInsertedObjects:(BOOL)flag
If YES
then items will be selected upon insertion.
The default is YES
.
NSArrayController.h
Sets the sort descriptors for the receiver.
- (void)setSortDescriptors:(NSArray *)sortDescriptors
An array of NSSortDescriptor
objects, used by the receiver to arrange its content.
NSArrayController.h
Returns the receiver's array of sort descriptors.
- (NSArray *)sortDescriptors
The array of NSSortDescriptor
objects used by the receiver to arrange its content.
This property is observable using key-value observing.
NSArrayController.h
© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-04-09)