register(_:forCellReuseIdentifier:)
dequeueReusableCell(withIdentifier:)
cellForRowAt
메서드는 재사용 가능한 셀이 있는지 먼저 확인하고, 있다면 재사용하며, 없다면 새로 만든다.dequeueReusableCell(withIdentifier:)
공식 문서에 의하면, 성능상의 이유로 인해 테이블 뷰의 데이터 소스는 cellForRowAt
메서드에서 셀을 배정할 때, 전반적으로 UITableViewCell
오브젝트를 재사용해야 한다.dequeueReusableCell(withIdentifier:)
메서드는 재사용 가능한 테이블 뷰 셀 오브젝트를 반환한다.prepareForReuse()
메서드를 불러오고 재사용한다.init(style:reuseIdentifier:)
을 불러와 새로운 셀을 생성한다.register(_:forCellReuseIdentifier:)
메서드는, 새로운 셀을 만들 때 사용할 클래스를 "등록" 한다.reuseIdentifier
를 가진 셀의 클래스를 nil
로 정해주면 된다.reuseIdentifier
를 가진 셀이 사용할 클래스 정보를 덮어쓰기 때문.reuseIdentifier
가 가장 중요한 것 같은 느낌이 든다..?https://developer.apple.com/documentation/uikit/uitableview/1614891-dequeuereusablecell
https://developer.apple.com/documentation/uikit/uitableview/1614888-register