添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
[Foundation.Register("UICollectionViewCell", true)]
[ObjCRuntime.Introduced(ObjCRuntime.PlatformName.iOS, 6, 0, ObjCRuntime.PlatformArchitecture.All, null)]
public class UICollectionViewCell : UIKit.UICollectionReusableView
type UICollectionViewCell = class
    inherit UICollectionReusableView
UICollectionViewCell

UICollectionViewCell 是可重用的视图,在集合视图呈现的数据集中显示单个项。 作为 的 UICollectionReusableView 子类型,它们应由包含 UICollectionView 的 来管理。

类 UICollectionView 旨在处理大型数据集,同时遵守 iOS 设备的资源限制。 为此, UICollectionView 维护类型的 UICollectionReusableView 组件视图的重用队列,仅实例化绝对必要的数量,并将 中 UICollectionViewCell 不再可见的值替换为即将滚动到屏幕上的 适合 UICollectionViewCell 的值。

重用队列意味着 (和其他) 子类型的 UICollectionReusableView 生命周期 UICollectionViewCell 异常。 不是由应用程序开发人员分配它们并允许垃圾回收器适当地清查它们, UICollectionReusableView 而是由 UICollectionView 分配,而不再在屏幕上的那些不再位于屏幕上的,无需解除分配即可重复使用。 (有关更多讨论,请参阅 UICollectionView 。)

每个单元格都是 类的 UICollectionViewCell 一个实例,该类由三个不同的视图组成,如下图所示,取自“集合视图简介”指南:

上述屏幕截图中的单元格是通过继承自 UICollectionView 并设置 ContentView 、 和 BackgroundView 属性创建的, ContentView 如以下代码所示:

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);          
 

由于 可以在不重新分配的情况下重复使用 的 UICollectionViewCell 单个实例,因此应用程序开发人员可能还必须使用 GetCell(UICollectionView, NSIndexPath) 方法动态调整各方面,如以下代码所示,取自“集合视图简介”示例。 animalCell 是 的子类型的 UICollectionViewCell 实例, animal 而 变量引用模型类的实例。 方法 GetCell(UICollectionView, NSIndexPath) 设置 的 UICollectionViewCell 可视方面以符合 animal 数据,在本例中,请相应地设置 属性 Image 。

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;
		

使用 NSString keyPath) 注册在外部 (观察到的对象。   观察到的更改将调度到观察者的 对象 ObserveValue(NSString, NSObject, NSDictionary, IntPtr) 方法。

(继承自 NSObject)

使用 string keyPath) 注册在外部 (观察到的对象。   观察到的更改将调度到观察者的 对象 ObserveValue(NSString, NSObject, NSDictionary, IntPtr) 方法。

(继承自 NSObject)