Skip to content

UICollectionView

UICollectionView 是用于展示大量条目的滚动视图,继承自 UIScrollView。在插件运行时通常配合 dataSourcecollectionViewLayout 使用,通过“注册 → 复用”机制创建 cell,并在需要时对 section/item 做增删改或批量更新。

属性类型说明
itemnumber只读。运行时暴露的整数属性(常见于布局/交互状态字段)。
backgroundViewUIView背景视图。
allowsMultipleSelectionboolean是否允许多选。
allowsSelectionboolean是否允许选中。
dataSourceid数据源对象(由插件自定义对象承担)。
collectionViewLayoutUICollectionViewLayout当前布局对象。
方法参数返回值说明
registerClassForCellWithReuseIdentifier(cellClass, identifier)cellClass: id, identifier: stringvoid注册 cell 类型与复用标识符。
registerClassForSupplementaryViewOfKindWithReuseIdentifier(viewClass, elementKind, identifier)viewClass: id, elementKind: string, identifier: stringvoid注册 supplementary view。
dequeueReusableCellWithReuseIdentifierForIndexPath(identifier, indexPath)identifier: string, indexPath: NSIndexPathid取出复用 cell。
dequeueReusableSupplementaryViewOfKindWithReuseIdentifierForIndexPath(elementKind, identifier, indexPath)elementKind: string, identifier: string, indexPath: NSIndexPathid取出复用 supplementary view。
方法参数返回值说明
indexPathsForSelectedItems()NSArray当前选中项的 indexPath 列表。
deselectItemAtIndexPathAnimated(indexPath, animated)indexPath: NSIndexPath, animated: booleanvoid取消选中。
visibleCells()NSArray当前可见的 cell 列表。
indexPathsForVisibleItems()NSArray当前可见项的 indexPath 列表。
方法参数返回值说明
reloadData()void重新加载数据。
setCollectionViewLayoutAnimated(layout, animated)layout: UICollectionViewLayout, animated: booleanvoid切换布局(可动画)。
setCollectionViewLayoutAnimatedCompletion(layout, animated, completion)layout: UICollectionViewLayout, animated: boolean, completion: (finished: boolean) => voidvoid切换布局并在完成后回调。
finishInteractiveTransition()void结束交互式转场。
cancelInteractiveTransition()void取消交互式转场。
方法参数返回值说明
numberOfSections()numbersection 数量。
numberOfItemsInSection(section)section: numbernumber指定 section 的 item 数量。
layoutAttributesForItemAtIndexPath(indexPath)indexPath: NSIndexPathUICollectionViewLayoutAttributes获取指定 item 的布局属性。
layoutAttributesForSupplementaryElementOfKindAtIndexPath(kind, indexPath)kind: string, indexPath: NSIndexPathUICollectionViewLayoutAttributes获取 supplementary element 的布局属性。
indexPathForItemAtPoint(point)point: { x: number, y: number }NSIndexPath | null根据点坐标反查 item 的 indexPath。
indexPathForCell(cell)cell: UICollectionViewCellNSIndexPath | null根据 cell 反查 indexPath。
cellForItemAtIndexPath(indexPath)indexPath: NSIndexPathUICollectionViewCell | null返回当前已创建并可见的 cell(不可见则可能为 null)。
方法参数返回值说明
insertSections(sections)sections: NSIndexSetvoid插入 section。
deleteSections(sections)sections: NSIndexSetvoid删除 section。
reloadSections(sections)sections: NSIndexSetvoid刷新 section。
moveSectionToSection(section, newSection)section: number, newSection: numbervoid移动 section。
insertItemsAtIndexPaths(indexPaths)indexPaths: NSArrayvoid插入 item。
deleteItemsAtIndexPaths(indexPaths)indexPaths: NSArrayvoid删除 item。
reloadItemsAtIndexPaths(indexPaths)indexPaths: NSArrayvoid刷新 item。
moveItemAtIndexPathToIndexPath(indexPath, newIndexPath)indexPath: NSIndexPath, newIndexPath: NSIndexPathvoid移动 item。
performBatchUpdatesCompletion(updates, completion)updates: () => void, completion: (finished: boolean) => voidvoid在一次批量更新中执行多项增删改,并在完成后回调。

当前运行时未额外暴露 UICollectionView 的类成员。

头文件 API 清单

正在加载…

协议:,来源: