iOS에서 기본적인 view를 구성할 때 가장 빈번하게 사용되는
UICollectionview
에 대해서 알아봅니다.
class UICollectionView: UIScrollView
class UICollectionViewController: UIViewController
var dataSource: UICollectionViewDataSource
Required
func collectionView(UICollectionView, numberOfItemsInSection section: Int) -> Int
func collectionView(UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell
dequeueReusableCell(withReuseIdentifier:for:)
를 호출한다. (무조건 cell을 리턴함.)Optional
func numberOfSections(in: UICollectionView) -> Int
func collectionView(UICollectionView, viewForSupplementaryElementOfKind: String, at: IndexPath) -> UICollectionReusableView
func collectionView(UICollectionView, canMoveItemAt: IndexPath) -> Bool
func collectionView(UICollectionView, moveItemAt: IndexPath, to: IndexPath)
func indexTitles(for: UICollectionView) -> [String]?
func collectionView(UICollectionView, indexPathForIndexTitle: String, at: Int) -> IndexPath
protocol UICollectionViewDataSourcePrefetching
func collectionView(UICollectionView, prefetchItemsAt: [IndexPath])
method를 구현한다. 이 메소드는 collection View가 화면에 로드되고 셀을 로드할 준비가 끝나면 호출이 된다. 이 메소드에서 데이터를 비동기적으로 fetch한다.func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath]) {
for indexPath in indexPaths {
self.fetchData(index: indexPath.row)
}
}
func collectionView(UICollectionView, cellForItemAt: IndexPath)
에서 prefetch된 데이터를 활용하여 cell을 보여줄 준비를 한다.func collectionView(UICollectionView, cancelPrefetchingForItemsAt: [IndexPath])
메소드는 prefetch된 데이터가 필요없어졌을 때 (역 스크롤링 등) 호출되는 optional method다. 필요없어진 데이터를 정리해주면 된다.var contentView: UIView
var backgroundView: UIView?
var selectedBackgroundView: UIView?
var isSelected
var isHighlighted
func dragStateDidChange(UICollectionViewCell.DragState)
drag state: enum UICollectionViewCell.DragState
func register(AnyClass?, forCellWithReuseIdentifier: String)
func register(UINib?, forCellWithReuseIdentifier: String)
func register(AnyClass?, forSupplementaryViewOfKind: String, withReuseIdentifier: String)
func register(UINib?, forSupplementaryViewOfKind: String, withReuseIdentifier: String)
func dequeueReusableCell(withReuseIdentifier: String, for: IndexPath) -> UICollectionViewCell
func dequeueReusableSupplementaryView(ofKind: String, withReuseIdentifier: String, for: IndexPath) -> UICollectionReusableView