Protocol: UIDataSourceModelAssociation

Overview

The UIDataSourceModelAssociation protocol defines an interface for providing persistent references to data objects in your app. Your data source objects can adopt this protocol in order to assist a corresponding table or collection view during the state restoration process. Those classes use the methods of this protocol to ensure that the same data objects (and not just the same row indexes) are scrolled into view and selected.Returns the current index of the data object with the specified identifier. (required)Returns the string that uniquely identifies the data at the specified location in the view. (required)

Instance Method Summary (collapse)

Instance Method Details

- (NSIndexPath) indexPathForElementWithModelIdentifier(identifier, inView:view)

Returns the current index of the data object with the specified identifier. (required) During state restoration, view can call this method to locate objects that are not where they were expected to be. This can happen if the number of objects in the table is not the same as during the previous launch cycle. The view uses the information to ensure that the rows with the same data are once again selected or scrolled into view, even if those rows are in a different location now.

Parameters:

  • identifier (String)

    The identifier for the requested data object. Use this identifier to locate the matching object in your data source object. This is the same string that your app’s modelIdentifierForElementAtIndexPath:inView: method returned when encoding the data originally.

  • view (UIView)

    The view into which the object is being inserted.

Returns:

  • (NSIndexPath)

    The current index of the object whose data matches the value in identifier, or nil if the object was not found.

- (String) modelIdentifierForElementAtIndexPath(idx, inView:view)

Returns the string that uniquely identifies the data at the specified location in the view. (required) Use the provided information to locate the requested data object. From that object, extract a string that can be used later to identify the same piece of data again. The string you return must not be based on transient information, such as the pointer to the current object in memory; it must instead be tied to the underlying data. In fact, if two different in-memory objects represent the same piece of data in your app, they must both return the same model identifier string.

Parameters:

  • idx (NSIndexPath)

    The index path to the requested data object.

  • view (UIView)

    The view that contains the data object.

Returns:

  • (String)

    A string that uniquely identifies the data object.