[iOS] UICollectionView

.onNext("Volga")·2023년 1월 21일
0

iOS

목록 보기
5/7

UICollectionView

UIKit 프레임 워크에서 사용되는 UICollectionView Class에 대해 공식 문서를 번역해보고 공부해 봅니다.

An object that manages an ordered collection of data items and presents them using customizable layouts.

UICollectionView 객체는 정렬된 데이터의 컬렉션 items를 관리하고 그것들을 customizable layouts를 사용해서 보여줍니다.

Declaration

@MainActor class UICollectionView: UIScrollView

선언부에는 @MainActor 노테이션과, UIScrollView를 상속한다는 것을 확인 할 수 있습니다.

@MainActor 노테이션 같은 경우에는, ClassBehaviorMain Thread에서 동작하게 하는 노테이션입니다. (문서참조)

또한, UIScrollView를 상속한다는 것에 대해서, 어느정도 UIScrollView의 속성들을 가지고 있다고 유추 해 볼수 있겠습니다!

Overview

When you add a collection view to your user interface, your app’s main job is to manage the data associated with that collection view. The collection view gets its data from the data source object, stored in the collection view’s dataSource property. For your data source, you can use a UICollectionViewDiffableDataSource object, which provides the behavior you need to simply and efficiently manage updates to your collection view’s data and user interface. Alternatively, you can create a custom data source object by adopting the UICollectionViewDataSource protocol.

Data in the collection view is organized into individual items, which you can group into sections for presentation. An item is the smallest unit of data you want to present. For example, in a photos app, an item might be a single image. The collection view presents items onscreen using a cell, which is an instance of the UICollectionViewCell class that your data source configures and provides.

In addition to its cells, a collection view can present data using other types of views. These supplementary views can be, for example, section headers and footers that are separate from the individual cells but still convey information. Support for supplementary views is optional and defined by the collection view’s layout object, which is also responsible for defining the placement of those views.

Besides embedding a UICollectionView in your user interface, you use the methods of the collection view to ensure that the visual presentation of items matches the order in your data source object. A UICollectionViewDiffableDataSource object manages this process automatically. If you’re using a custom data source, then whenever you add, delete, or rearrange data in your collection, you use the methods of UICollectionView to insert, delete, and rearrange the corresponding cells.

You also use the collection view object to manage the selected items, although for this behavior the collection view works with its associated delegate object.

너무기네요;; 짧게 짧게 요약을 좀 해봅시다..!

  • Collection Viewdatadata source object에서 가져옵니다.
  • Collection ViewdataCollection Viewdata Source Property에 저장합니다.
  • 또한 data source를 위해, UICollectionViewDiffableDataSource객체를 사용할수 있습니다.
    • UICollectionViewDiffableDataSource는 간단하고 효율적인 updates관리를 UI에 제공합니다.
    • UIColletionView에서 시각적인 순서와 Data Source 객체의 순서를 자동적으로 관리해줍니다. (Identifiable)
  • 또한, UICollectionViewDataSource 프로토콜을 채택함으로서 커스텀 data source object를 만들수 있습니다.
  • Collection View의 데이터는 개별적인 Item으로 구성이 됩니다.
    • Item은 표시하고자 하는 데이터의 최소 단위 입니다.
  • 또한 이러한 Item들을 Section으로 그루핑해서 보여지게 만듭니다!
  • Collection ViewCell 외에도, 다른 유형의 views를 사용해서 데이터를 표시하는게 가능합니다. (ex, footer, header)

정리

  • Overview에 크게 제시되어있는 내용말고도 Layout, Cell and Supplementary views, Data prefetching, Reorder items interactivitvely 등 여러가지 내용이 더 있습니다.
  • 나머지 내용들에 대해서는 추가적으로 정리하는 부분을 고려해서 추가해보겠습니다.

단어 보충

supplementary views가 무엇인지 잘몰라서 서칭을 좀 해봤습니다.
일각에서는 colletion viewHeader + Footer를 합쳐서 spplementary views라고 부른다고 하네요!

profile
iOS 개발자 volga입니다~

0개의 댓글