MonoTouch.UIKit.UICollectionViewCell Class
Represents a reusable content view in the set being presented by the MonoTouch.UIKit.UICollectionView.

See Also: UICollectionViewCell Members

Syntax

[MonoTouch.Foundation.Register("UICollectionViewCell", true)]
[MonoTouch.ObjCRuntime.Availability(Introduced=MonoTouch.ObjCRuntime.Platform.iOS_6_0)]
public class UICollectionViewCell : UICollectionReusableView

See Also

UICollectionView

Remarks

MonoTouch.UIKit.UICollectionViewCells are reusable views that present a single item in the data set that is being presented by the collection view. As subtypes of MonoTouch.UIKit.UICollectionReusableView, they are expected to be managed by their containing MonoTouch.UIKit.UICollectionView.

The MonoTouch.UIKit.UICollectionView class is designed to work with large datasets while respecting the resource limitations of iOS devices. To do this, the MonoTouch.UIKit.UICollectionView maintains a reuse queue of component views of type MonoTouch.UIKit.UICollectionReusableView, instantiating only as many as are strictly necessary and replacing values in MonoTouch.UIKit.UICollectionViewCells that are no longer visible with values appropriate to MonoTouch.UIKit.UICollectionViewCells that are about to scroll onto the screen.

The reuse queue implies an unusual lifecycle for MonoTouch.UIKit.UICollectionViewCells (and other subtypes of MonoTouch.UIKit.UICollectionReusableView). Rather than the application developer allocating them and allowing the garbage collector to scavenge them appropriately, MonoTouch.UIKit.UICollectionReusableViews are allocated by a MonoTouch.UIKit.UICollectionView and those that are no longer on-screen are reused without deallocation. (See MonoTouch.UIKit.UICollectionView for more discussion.)

Each cell is an instance of the MonoTouch.UIKit.UICollectionViewCell class, which is comprised of three different views, as shown in the figure below, taken from the "Introduction to Collection Views" guide:

The Cells in the screenshot above are created by inheriting from MonoTouch.UIKit.UICollectionView and setting the UICollectionView.ContentView, UICollectionView.ContentView, and UICollectionView.BackgroundView properties as shown in the following code:

C# Example

          BackgroundView = new UIView{BackgroundColor = UIColor.Orange};
          
          SelectedBackgroundView = new UIView{BackgroundColor = UIColor.Green};
          
          ContentView.Layer.BorderColor = UIColor.LightGray.CGColor;
          ContentView.Layer.BorderWidth = 2.0f;
          ContentView.BackgroundColor = UIColor.White;
          ContentView.Transform = CGAffineTransform.MakeScale (0.8f, 0.8f);
          
          imageView = new UIImageView (UIImage.FromBundle ("placeholder.png"));
          imageView.Center = ContentView.Center;
          imageView.Transform = CGAffineTransform.MakeScale (0.7f, 0.7f);
          
          ContentView.AddSubview (imageView);          
        

Since an individual instance of MonoTouch.UIKit.UICollectionViewCell may be reused without being re-allocated, the application developer may also have to adjust aspects dynamically using the UICollectionViewSource.GetCell method, as shown in the following code, taken from the "Introduction to Collection Views" sample. The animalCell is an instance of a subtype of MonoTouch.UIKit.UICollectionViewCell while the animal variable refers to an instance of a model class. The UICollectionViewSource.GetCell method sets visual aspects of the MonoTouch.UIKit.UICollectionViewCell to conform to the animal data, in this case, setting an Image property appropriately.

C# Example

public override UICollectionViewCell GetCell (UICollectionView collectionView, MonoTouch.Foundation.NSIndexPath indexPath)
{
  var animalCell = (AnimalCell) collectionView.DequeueReusableCell (animalCellId, indexPath);

  var animal = animals [indexPath.Section * (animals.Count / SectionCount) + indexPath.Row];

  animalCell.Image = animal.Image;

  return animalCell;
}          
        

Related content

Requirements

Namespace: MonoTouch.UIKit
Assembly: monotouch (in monotouch.dll)
Assembly Versions: 0.0.0.0