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 |
NSObjectController is a Cocoa bindings compatible controller class. Properties of the content object of an instance of this class can be bound to user interface elements to access and modify their values.
By default the content object of an NSObjectController instance is NSMutableDictionary. This allows a single NSObjectController instance to be used to manage many different properties referenced by key value paths. The default content object class can be changed by calling setObjectClass
, which subclassers must override.
Creates and returns an empty NSObjectController.
public NSObjectController
()
Creates and returns an NSObjectController with the specified content.
public NSObjectController
(Object content)
Creates a new object of the class specified by objectClass
and sets it as the receiver’s content object using addObject
.
public void add
(Object sender)
The sender is typically the object that invoked this method.
Sets object as the receiver’s content object.
public void addObject
(Object object)
If the receiver's content is bound to another object or controller through a relationship key, the relationship of the “master” object is changed.
Returns true
if the receiver invokes prepareContent
automatically when the receiver is loaded from a nib.
public boolean automaticallyPreparesContent
()
If the receiver has a mananged object context set, it automatically fetches data from the managed object context using the current fetch predicate. The default is true
..
Returns true
if an object can be added to the receiver using add
.
public boolean canAdd
()
Bindings can use this method to control the enabling of user interface objects.
This property is observable using key-value observing.
Returns true
if an object can be removed from the receiver using remove
.
public boolean canRemove
()
Bindings can use this method to control the enabling of user interface objects.
This property is observable using key-value observing.
Returns the receiver’s content object.
public Object content
()
This property is observable using key-value observing.
Returns the entity name used by the receiver to create new objects.
public NSString entityName
()
Causes the receiver to fetch the data objects specified by the entity name and fetch predicate.
public void fetch
(Object sender)
Returns true
if the receiver allows adding and removing objects.
public boolean isEditable
()
This property is observable using key-value observing.
Returns the receiver’s managed object context.
public NSManagedObjectContext managedObjectContext
()
Creates and returns a new object of the class specified by objectClass
.
public Object newObject
()
This method is called when adding and inserting objects if setAutomaticallyPreparesContent
is true
.
The default implementation assumes the class returned by objectClass
has a standard initialization method.
Returns the class used when creating new objects.
public Class objectClass
()
The default class is NSMutableDictionary.
This property is observable using key-value observing.
Typically overridden by subclasses that require additional control over the creation of new objects.
public void prepareContent
()
Subclasses that implement this method are responsible for creating the new content object and setting it as the receiver’s content object. This method is only called if setAutomaticallyPreparesContent
has been set to true
.
Removes the receiver’s content object using removeObject
.
public void remove
(Object sender)
The sender is typically the object that invoked this method.
If object is the receiver’s content object, the receiver’s content is set to null
.
public void removeObject
(Object object)
If the receiver's content is bound to another object or controller through a relationship key, the relationship of the ‘master’ object is cleared.
Returns an array of all objects to be affected by editing.
public NSArray selectedObjects
()
If the receiver supports a selection mechanism the array contains key value coding compliant proxies of the selected objects; otherwise proxies for all content objects are returned. If the receiver is a concrete instance of NSObjectController, returns an array containing the receiver’s content object.
You should avoid registering for key-value observing changes for key paths that pass through this method, that is selectedObjects.firstName
. Using the proxy returned by the selection
method is better for performance.
This property is observable using key-value observing.
Returns a proxy object representing the receiver’s selection.
public Object selection
()
If a value requested from the selection proxy using key-value coding returns multiple objects, the controller has no selection, or the proxy is not key-value coding compliant for the requested key, the appropriate marker (MultipleValuesMarker
, NoSelectionMarker
or NotApplicableMarker
) is returned. Otherwise, the value of the key is returned. This proxy is fully key-value coding compliant.
This property is observable using key-value observing.
Sets whether the receiver creates and inserts new content objects automatically when loading from a nib file.
public void setAutomaticallyPreparesContent
(boolean flag)
If flag is true
and the receiver is not using a managed object context, prepareContent
is used to create the content object. If flag is true
and a managed object context is set, the initial content is fetched from the managed object context using the current fetch predicate.
Setting flag to true
is the same as checking the “Automatically Prepares Content” option in the Interface Builder controller inspector.
Set’s the receiver’s content object to content.
public void setContent
(Object content)
Sets whether the receiver allows adding and removing objects.
public void setEditable
(boolean flag)
The default is true
.
Sets the receiver’s entity name to entityName.
public void setEntityName
(NSString entityName)
Sets the receiver’s fetch predicate to predicate.
public void setFetchPredicate
(NSPredicate predicate)
Sets the receiver’s managed object context to managedObjectContext.
public void setManagedObjectContext
(NSManagedObjectContext managedObjectContext)
Sets the object class used when creating new objects.
public void setObjectClass
(Class objectClass)
NSObjectController’s default implementation assumes that instances of objectClass are initialized using a method that takes no arguments.
Validates menu item anItem, returning true
if it should be enabled, false
otherwise.
public boolean validateMenuItem
(_NSObsoleteMenuItemProtocol anItem)
For example, if canAdd
returns false
, menu items with the add
action and the receiver as the target object are disabled.
© 1997, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-02-01)