Описание тега reuseidentifier
Great iOS apps must perform well in memory– and processor-constrained environments while displaying rich, high resolution content. Reuse identifiers are part of a caching mechanism employed by a few of the core data views provided by Apple to minimize the number of views to initially construct, based on the data currently visible in a scrolling view, without requiring constant reconstruction of views as the user scrolls or pans through data.
The following view classes employ reuse identifiers:
-
UITableView
, for display of itsUITableViewCell
rows -
UICollectionView
, for display of itsUICollectionViewCell
and supplementaryUICollectionReusableView
items -
MKMapView
, for display of itsMKAnnotationView
annotations
The programmer first identifies the class of the view to use for a given reuse identifier. This can be done in a few ways:
- By configuring prototype cell views with reuse identifiers and class names in a storyboard
- By mapping reuse identifiers to classes or nibs in methods such as
registerClass:forReuseIdentifier:
- By manually instantiating new cell or annotation objects with a given reuse identifier value
When the table/collection/map view displays the initial set of data, or it displays new data due to user interaction, it will ask its delegate to create views for each item to display. The delegate will typically use a "dequeue" method such as dequeueReusableCellWithIdentifier:
to get an instance of the right type of view, then customize the view for the specific data to display, and return that view. If there is an existing view object with the given reuse identifier that is not currently visible on screen, it may be returned from the "dequeue" method so that it can be reused; otherwise, a new view object will be created with the given reuse identifier.