Next Page > Hide TOC

NSCollectionView Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AppKit.framework
Availability
Available in Mac OS X v10.5 and later.
Declared in
NSCollectionView.h

Overview

NSCollectionView displays an array of content as a grid of views.

Tasks

Modifying the Collection View Item

Working with the Responder Chain

Setting the Content

Setting the Selection Mode

Laying out the Collection View

Modifying the Visual Properties

Instance Methods

allowsMultipleSelection

Returns a Boolean value that indicates whether the receiver allows the user to select more than one item at a time.

- (BOOL)allowsMultipleSelection

Return Value

YES if the receiver allows the user to select more than one column or row at a time, otherwise NO.

Availability
Declared In
NSCollectionView.h

backgroundColors

Return the receiver’s background colors.

- (NSArray *)backgroundColors

Return Value

Returns an array containing the receiver’s background colors.

Availability
Declared In
NSCollectionView.h

content

Returns the receiver’s content object.

- (NSArray *)content

Return Value

An array containing the receiver’s content.

Discussion

This property is observable using key-value observing.

Availability
Declared In
NSCollectionView.h

isFirstResponder

Returns whether the receiver is the first responder.

- (BOOL)isFirstResponder

Return Value

YES if the receiver is the first responder, otherwise NO.

Special Considerations

This method is fully key-value observing compliant.

Availability
Declared In
NSCollectionView.h

isSelectable

Returns a Boolean value that indicates whether the receiver allows the user to select items, NO if it doesn’t.

- (BOOL)isSelectable

Return Value

YES if the receiver allows the user to select items, otherwise NO.

Availability
Declared In
NSCollectionView.h

itemPrototype

Returns the receiver’s collection view item prototype.

- (NSCollectionViewItem *)itemPrototype

Return Value

The receiver’s collection view item prototype.

Availability
Declared In
NSCollectionView.h

maxItemSize

Returns the maximum size used to display individual collection view items in the grid

- (NSSize)maxItemSize

Return Value

The maximum size, measured in points, used to display individual collection view items.

Availability
Declared In
NSCollectionView.h

maxNumberOfColumns

Returns the maximum number of columns the receiver will display.

- (NSUInteger)maxNumberOfColumns

Return Value

The maximum number of columns the receiver will display.

Availability
Declared In
NSCollectionView.h

maxNumberOfRows

Returns the maximum number of rows the receiver will display.

- (NSUInteger)maxNumberOfRows

Return Value

The maximum number of rows the receiver will display.

Availability
Declared In
NSCollectionView.h

minItemSize

Returns the minimum size used to display individual collection view items in the grid.

- (NSSize)minItemSize

Return Value

The minimum size, measured in points, used to display individual collection view items.

Availability
Declared In
NSCollectionView.h

newItemForRepresentedObject:

Returns the collection view item that is used for the specified object.

- (NSCollectionViewItem *)newItemForRepresentedObject:(id)object

Parameters
object

The content object that the collection view item will represent.

Return Value

An initialized collection view item with the specified object and the appropriate view set. The collection view item should not be autoreleased.

Discussion

Subclasses can override this method if the collection view items are not generated from a prototype or if the prototype view needs to be modified. The subclass is responsible for setting the view and representedObject of the new collection view item.

Availability
Declared In
NSCollectionView.h

selectionIndexes

Returns an index set containing the indexes of the receiver’s currently selected objects in the content array.

- (NSIndexSet *)selectionIndexes

Return Value

An index set containing the indexes of the receiver’s currently selected objects in the content array.

Discussion

This property is observable using key-value observing.

Availability
Declared In
NSCollectionView.h

setAllowsMultipleSelection:

Controls whether the user can select multiple items at a time.

- (void)setAllowsMultipleSelection:(BOOL)flag

Parameters
flag

YES to allow the user to select multiple items, otherwise NO.

Availability
Declared In
NSCollectionView.h

setBackgroundColors:

Sets the receiver's background colors to the specified array of colors.

- (void)setBackgroundColors:(NSArray *)colors

Parameters
colors

An array containing the background colors for the receiver.

Discussion

Passing an empty array or nil resets the background colors to their default values provided by controlAlternatingRowBackgroundColors.

Availability
Declared In
NSCollectionView.h

setContent:

Sets the receiver’s content array.

- (void)setContent:(NSArray *)content

Parameters
content

An array containing the receiver’s content.

Discussion

The content array can also be provided by creating a binding between the receiver’s NSContentBinding and an array controller’s arrangedObjects method.

Availability
Declared In
NSCollectionView.h

setItemPrototype:

Sets the reciever’s item prototype to the specified collection view item.

- (void)setItemPrototype:(NSCollectionViewItem *)prototype

Parameters
prototype

The collection view item used as the prototype by the receiver.

Availability
Declared In
NSCollectionView.h

setMaxItemSize:

Sets the maximum size used to display individual collection view items in the grid.

- (void)setMaxItemSize:(NSSize)size

Parameters
size

The new maximum size, measured in points, with which to display individual collection view items.

Discussion

Setting the size to (0,0) specifies no maximum grid size. The default is (0.0). If the view in the receiver’s collection view item prototype is resizable you should set this to the maximum size that the view should be displayed using.

Availability
Declared In
NSCollectionView.h

setMaxNumberOfColumns:

Sets the maximum number of columns the receiver will display

- (void)setMaxNumberOfColumns:(NSUInteger)number

Parameters
number

The maximum number of columns the receiver will display.

Discussion

Setting to 0 specifies no maximum number of columns. Defaults to 0.

It is possible for a NSCollectionView instance to specify both the maximum number of rows and a maximum number of columns. If the number of content objects exceeds the number of displayable items (n=maxNumberOfRows * maxNumberOfColumns) only the first n items of the content array are displayed.

Availability
Declared In
NSCollectionView.h

setMaxNumberOfRows:

Sets the maximum number of rows the receiver will display.

- (void)setMaxNumberOfRows:(NSUInteger)number

Parameters
number

The maximum number of rows the receiver can display.

Discussion

Setting to 0 specifies no maximum number of rows. Defaults to 0.

It is possible for a NSCollectionView instance to specify both the maximum number of rows and a maximum number of columns. If the number of content objects exceeds the number of displayable items (n=maxNumberOfRows * maxNumberOfColumns) only the first n items of the content array are displayed.

Availability
Declared In
NSCollectionView.h

setMinItemSize:

Sets the minimum size used to display individual layout items in the grid.

- (void)setMinItemSize:(NSSize)size

Parameters
size

The new minimum size, measured in points, with which to display individual layout items.

Discussion

The default is (0.0). If the view in the receiver’s collection view item prototype is resizable you should set this to the minimum size that the view should be displayed using.

Availability
Declared In
NSCollectionView.h

setSelectable:

Controls whether the receiver allows the user to select items.

- (void)setSelectable:(BOOL)flag

Parameters
flag

If flag is YES, the receiver allows the user to select items; if flag is NO, it doesn’t.

Discussion

You can set selections programmatically regardless of this setting.

Availability
Declared In
NSCollectionView.h

setSelectionIndexes:

Sets the receiver’s selection using the specified indexes.

- (void)setSelectionIndexes:(NSIndexSet *)indexes

Parameters
indexes

The set of selection indexes for the receiver.

Discussion

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.

Availability
Declared In
NSCollectionView.h

Next Page > Hide TOC


© 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-12-11)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.