Important: The information in this document is obsolete and should not be used for new development.
Inherits from | |
Implements | |
Package | com.apple.cocoa.application |
Availability | Available in Mac OS X v10.3 and later. |
Companion guides |
The NSArrayController is a bindings compatible class that manages an array of objects. It provides selection management and sorting capabilities.
setAvoidsEmptySelection
avoidsEmptySelection
setClearsFilterPredicateOnInsertion
preservesSelection
setPreservesSelection
alwaysUsesMultipleValuesMarker
setAlwaysUsesMultipleValuesMarker
setSelectsInsertedObjects
selectsInsertedObjects
setSelectionIndexes
selectionIndexes
addSelectionIndexes
removeSelectionIndexes
setSelectedObjects
selectedObjects
addSelectedObjects
removeSelectedObjects
selectNext
canSelectNext
selectPrevious
canSelectPrevious
Creates and returns an empty NSArrayController.
public NSArrayController
()
Creates and returns an NSArrayController with the specified content.
public NSArrayController
(Object content)
Adds object to the receiver’s content array and the arranged objects array.
public void addObject
(Object object)
Adds objects to the receiver’s content array.
public void addObjects
(NSArray objects)
If selectsInsertedObjects
returns true
, which is 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 false
before adding the objects with addObjects
.
Adds objects from the receiver’s content array to the current selection, returning true
if the selection was changed.
public boolean addSelectedObjects
(NSArray objects)
Attempting to change the selection may cause a commitEditing
message which fails, thus denying the selection change.
Adds the objects at the specified indexes in the receiver’s content array to the current selection, returning true
if the selection was changed.
public boolean addSelectionIndexes
(NSIndexSet indexes)
Attempting to change the selection may cause a commitEditing
message which fails, thus denying the selection change.
Returns whether the receiver always returns the multiple values marker when multiple objects are selected, even if the selected items have the same value.
public boolean alwaysUsesMultipleValuesMarker
()
The default is false.
This property is observable using key-value observing.
Returns an array containing the receiver’s content objects arranged using arrangeObjects
public Object arrangedObjects
()
.
This property is observable using key-value observing.
Returns an array containing the content of the objects array arranged according to the receiver’s sortDescriptors
.
public NSArray arrangeObjects
(NSArray objects)
Subclasses should override this method to use a different sort mechanism, provide custom object arrangement, or filter the objects.
Returns true
if the receiver requires that the content array attempt to maintain a selection at all times.
public boolean avoidsEmptySelection
()
The default is true
.
This property is observable using key-value observing.
Returns true
if an object can be inserted into the receiver’s content array.
public boolean canInsert
()
The result of this method can be used by a binding to enable user interface items.
This property is observable using key-value observing.
Returns true
if the next object, relative to the current selection, in the receiver’s content array can be selected.
public boolean 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.
Returns true
if the previous object, relative to the current selection, in the receiver’s content array can be selected.
public boolean 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.
Returns whether the receiver automatically clears an existing filter predicate when new items are inserted or added to the content.
public boolean clearsFilterPredicateOnInsertion
()
The default is true
.
This property is observable using key-value observing.
Returns the predicate used by the receiver to filter the array controller contents.
public NSPredicate filterPredicate
()
Returns null
if no filter predicate is set.
This property is observable using key-value observing.
Creates a new object of the class specified by objectClass
and inserts it into the receiver’s content array.
public void insert
(Object sender)
The sender is typically the object that invoked this method.
Inserts object into the receiver’s arranged objects array at the location specified by index, and adds it to the receiver’s content array.
public void insertObject
(Object object, int index)
Subclasses can override this method to provide customized arranged objects support.
Inserts objects into the receiver’s arranged objects array at the locations specified in indexes, and adds it to the receiver’s content array.
public void insertObjects
(NSArray objects, NSIndexSet indexes)
Returns whether the receiver will attempt to preserve the current selection then when the content changes.
public boolean preservesSelection
()
The default is true
.
This property is observable using key-value observing.
Removes the receiver’s selected objects from the content array.
public void remove
(Object object)
The sender is typically the object that invoked this method.
Removes object from the receiver’s content collection.
public void removeObject
(Object 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.
Removes the object at the specified index in the receiver’s arranged objects from the receiver’s content array.
public void removeObject
(int index)
Removes objects from the receiver’s content array.
public void removeObjects
(NSArray objects)
Removes the objects at the specified indexes in the receiver’s arranged objects from the content array.
public void removeObjects
(NSIndexSet indexes)
Removes objects from the receiver’s current selection, returning true
if the selection was changed.
public boolean removeSelectedObjects
(NSArray objects)
Attempting to change the selection may cause a commitEditing
message which fails, thus denying the selection change.
Removes the object as the specified indexes from the receiver’s current selection, returning true
if the selection was changed.
public boolean removeSelectionIndexes
(NSIndexSet indexes)
Attempting to change the selection may cause a commitEditing
message which fails, thus denying the selection change.
Returns an array containing the receiver’s selected objects.
public NSArray selectedObjects
()
This property is observable using key-value observing.
Returns the index of the first object in the receiver’s selection, NSArray.NotFound
if there is no selection.
public int selectionIndex
()
This property is observable using key-value observing.
Returns an index set containing the indexes of the receiver’s currently selected objects in the content array.
public NSIndexSet selectionIndexes
()
This property is observable using key-value observing.
Selects the next object, relative to the current selection, in the receiver’s arranged content.
public void selectNext
(Object sender)
The sender is typically the object that invoked this method.
Selects the previous object, relative to the current selection, in the receiver’s arranged content.
public void selectPrevious
(Object sender)
The sender is typically the object that invoked this method.
Returns whether the receiver selects inserted objects automatically.
public boolean selectsInsertedObjects
()
The default is true
.
This property is observable using key-value observing.
Sets whether the receiver always returns the multiple values marker when multiple objects are selected, even if they have the same value.
public void setAlwaysUsesMultipleValuesMarker
(boolean flag)
Setting flag to true
can increase performance if your application doesn’t allow editing multiple values. The default is false.
Sets whether the receiver will attempt to avoid an empty selection.
public void setAvoidsEmptySelection
(boolean)
If flag is true
then the receiver will maintain a selection unless there are no objects in the content array. The default is true
.
Sets whether the receiver automatically clears an existing filter predicate when a new object is inserted or added to the content array.
public void setClearsFilterPredicateOnInsertion
(boolean flag)
The default is true
.
Sets the predicate used to filter the contents of the receiver to filterPredicate, replacing any existing filter predicate.
public void setFilterPredicate
(NSPredicate filterPredicate)
If filterPredicate is null any existing filter predicate is removed.
Sets whether the receiver will attempt to preserve selection when the content changes.
public void setPreservesSelection
(boolean flag)
If flag is true
then the selection will be preserved, if possible. The default is true
.
Sets objects as the receiver’s current selection, returning true
if the selection was changed.
public boolean setSelectedObjects
(NSArray objects)
Attempting to change the selection may cause a commitEditing
message which fails, thus denying the selection change.
Sets the receiver’s current selection to index, returning true
if the selection was changed.
public boolean setSelectionIndex
(int index)
Attempting to change the selection may cause a commitEditing
message which fails, thus denying the selection change.
Sets the receiver’s current selection to the objects at indexes, returning true
if the selection was changed.
public boolean setSelectionIndexes
(NSIndexSet indexes)
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 NSIndexSet with indexes [0..count -1]. To deselect all indexes, pass an empty NSIndexSet.
Sets whether the receiver will automatically select objects as they are inserted.
public void setSelectsInsertedObjects
(boolean flag)
If flag is true
then items will be selected upon insertion. The default is true
.
Sets the sort descriptors used by the receiver to arrange objects to sortDescriptors.
public void setSortDescriptors
(NSArray sortDescriptors)
Returns an array of sort descriptors used by the receiver to arrange objects.
public NSArray sortDescriptors
()
This property is observable using key-value observing.
© 1997, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-02-01)