티스토리 뷰

반응형

Apple Developer Documentation - UITableViewDelegate

UITableViewDelegate

테이블 뷰에서 section의 header, footer를 관리하고 셀을 삭제하거나 위치를 바꾸고 그 외의 다른 작업을 수행하기 위한 메서드를 제공한다.

Declaration

protocol UITableViewDelegate

Overview

UITableViewDelegate 프로토콜을 사용해서 할 수 있는 일들

1. 테이블 뷰의 header, footer를 만들고 관리

2. 셀과 header, footer의 높이를 마음대로 조절

3. 더 나은 스크롤링을 위해 높이 조절

4. 셀의 콘텐츠를 나눈다

5. 셀의 선택에 대한 응답

6. 셀에 대한 스와이프나 그 외의 행동에 대해 응답

7. 테이블 콘텐츠를 수정하는 것을 지원

테이블 뷰의 셀과 section들은 NSIndexPath 객체에 의해 구분된다. 이와 관련된 내용은 아래에서 확인할 수 있다.

 

UITableViewDataSource

 

UITableViewDelegate 프로토콜 메서드

테이블 뷰의 셀 구성을 관리

func tableView(UITableView, willDisplay: UITableViewCell, forRowAt: IndexPath)
// 테이블 뷰의 특정 셀이 화면에 나타나기 직전에 수행될 명령을 정의 할 수 있다

func tableView(UITableView, indentationLevelForRowAt: IndexPath) -> Int
// 지정된 section의 행에 대해 얼마나 들여쓰기를 했는지 알려준다

func tableView(UITableView, shouldSpringLoadRowAt: IndexPath, 
              with: UISpringLoadedInteractionContext) -> Bool
// 

셀 이 선택되는 것에 대한 반응

func tableView(UITableView, willSelectRowAt: IndexPath) -> IndexPath?
// index에 해당하는 셀이 선택된 상태가 되도록 설정
// 만약 선택될 수 없는 상태로 설정된 셀이라면 nil 반환

func tableView(UITableView, didSelectRowAt: IndexPath)
// 델리게이트에 해당 셀이 선택되었다고 알려준다

func tableView(UITableView, UITableView, willDeselectRowAt: IndexPath) -> IndexPath?
// index에 해당하는 셀이 선택되지 않은 상태가 되도록 설정
// 만약 선택되지 않을 수 없는 상태로 설정된 셀이라면 nil 반환

func tableView(UITableView, didDeselectRowAt: IndexPath)
// 델리게이트에 해당 셀이 선택해제되었다고 알려준다.

func tableView(UITableView, shouldBeginMultipleSelectionInteractionAt: IndexPath) -> Bool
// 테이블 뷰의 아이템들을 two-finger pan gesture로 선택할 수 있는지 알려준다

func tableView(UITableView, didBeginMultipleSelectionInteractionAt: IndexPath)
// 사용자가 테이블 뷰의 아이템들을 two-finger pan gesture로 선택하기 시작했다고 
// 델리게이트에게 알려준다

func tableViewDidEndMultipleSelectionInteraction(UITableView)
// 사용자가 테이블 뷰에서 two-finger pan gesture를 중단했다고 델리게이트에 알려준다.

Header, Footer를 관리하는 메서드

func tableView(UITableView, viewForHeaderInSection: Int) -> UIView?
// 테이블 뷰 특정 Section의 Header를 보여준다 

func tableView(UITableView, view ForFooterInSection: Int) -> UIView?
// 테이블 뷰 특정 Section의 Footer를 보여준다

func tableView(UITableView, willDisplayHeaderView: UIView, forSection: Int)
// 델리게이트에 특정 섹션의 header가 보여질 것이라고 알려준다

func tableView(UITableView, willDisplayFooterView: UIView, forSection: Int)
// 델리게이트에 특정 섹션의 footer가 보여질 것이라고 알려준다

Header, Footer의 높이를 가져오는 메서드

func tableView(UITableView, heightForRowAt: IndexPath) -> CGFloat
// 특정 index의 행의 높이를 가져온다

func tableView(UITableView, heightHeaderInSection: Int) -> CGFloat
// 특정 섹션의 header의 높이를 가져온다

func tableView(UITableView, heightForFooterInSection: Int) -> CGFloat
// 특정 섹션의 footer의 높이를 가져온다

class let automaticDimention: CGFloat
// 지정된 차원의 기본값을 나타내는 상수

테이블 콘텐츠의 높이를 예상하는 메서드 (가변 높이일 경우)

func tableView(UITableView, estimatedHeightForRowAt: IndexPath) -> CGFloat
// 특정 index의 셀의 높이를 예상해준다

func tableView(UITableView, estimatedHeightForHeaderInSection: Int) -> CGFloat
// 특정 Section의 Header 높이를 예상해준다

func tableView(UITableView, estimatedHeightForFooterInSection: Int) -> CGFloat
// 특정 Section의 Footer 높이를 예상해준다

액세서리 뷰를 관리하는 메서드

func TableView(UITableView, accessoryButtonTappedForRowWith: IndexPath)
// 유저가 특정 index의 액세서리 뷰의 버튼을 눌렀다고 델리게이트에게 알려준다

Context 메뉴를 관리하는 메서드

Context menu 예시

func TableView(UITableView, contextMenuConfigurationForRowAt: IndexPath, poing: CGPoint) 
                  -> UIContextMenuConfiguration?
// 특정 index의 셀에서 사용된 context 메뉴를 가져온다

func TableView(UITableView, previewForDismissingContextMenuWithConfiguration: UIContextMenuConfiguration)
                  -> UITargetedPreview?
// context menu에서 선택된 뷰를 가져온다

func TableView(UITableView, previewForHighlightingContextMenuWithConfiguration: UIContextMenuConfiguration)
                  -> UITargetedPreView?
// 테이블의 default 뷰를 수정하기 위해 default 뷰를 가져온다 (?)

func tableView(UITableView, willDisplayContextMenu: UIContextMenuConfiguration, 
               animator: UIContextMenuInteractionAnimating?)
// context menu가 표시될 때 델리게이트에 알린다

func tableView(UITableView, willEndContextMenuInteraction: UIContextMenuConfiguration,
               animator: UIContextMenuInteractionAnimating?)
// context menu가 사라질 때 델리게이트에 알린다

func tableView(UITableView, willPerformPreviewActionForMenuWith: UIContextMenuConfiguration, 
               animator: UIContextMenuInteractionCommitAnimating)
// 사용자가 컨텍스트 메뉴에서 선택할 때 델리게이트에 알린다

행에서의 액션에 반응하는 메서드

func tableView(UITableView, leadingSwipeActionsConfigurationForRowAt: IndexPath) 
-> UISwipeActionsConfiguration?
// 셀에서 스와이프에 의해 생성되는 메뉴를 셀의 앞에 보여준다

func tableView(UITableView, trailingSwipeActionsConfigurationForRowAt: IndexPath) 
-> UISwipeActionsConfiguration?
// 셀에서 스와이프에 의해 생성되는 메뉴를 셀의 뒤에 보여준다

테이블 뷰의 셀들을 강조할 때 사용하는 메서드

func tableView(UITableView, shouldHighlightRowAt: IndexPath) -> Bool
// 특정 index의 셀이 강조되도 되는지 알려준다

func tableView(UITableView, didHighlightRowAt: IndexPath)
// 특정 index의 셀이 강조됐다고 델리게이트에게 알려준다

func tableView(UITableView, didUnhighlightRowAt: IndexPath)
// 특정 index의 셀의 강조가 제거됐다고 델리게이트에게 알려준다

테이블 뷰의 셀을 수정할 때 사용하는 메서드

func tableView(UITableView, willBeginEditingRowAt: IndexPath)
// 특정 index 셀이 수정될거라고 델리게이트에게 알려준다

func tableView(UITableView, didEndEditingRowAt: IndexPath?)
// 특정 index 셀의 수정을 종료했다고 델리게이트에게 알려준다

func tableView(UITableView, editingStyleForRowAt: IndexPath) -> UITableViewCell.EditingStyle
// 특정 index 셀의 Editing style을 가져온다

func tableView(UITableView, titleForDeleteConfirmationButtonForRowAt: IndexPath) -> String?
// 삭제 확인 버튼의 기본 title값을 변경한다

func tableView(UITableView, shouldIndentWhileEditingRowAt: IndexPath) -> Bool
// 테이블 뷰가 편집 모드일 때 특정 index 셀의 배경을 들여 쓸지에 대해 알려준다

테이블 뷰의 셀을 재배치할 때 사용하는 메서드

func tableView(UITableView, targetIndexPathForMoveFromRowAt: IndexPath, 
toProposedIndexPath: IndexPath) -> IndexPath
// 셀을 새로 이동한 index값을 알려준다 

테이블 뷰의 셀의 제거에 대한 메서드

func tableView(UITableView, didEndDisplaying: UITableViewCell, forRowAt: IndexPath)
// 특정 셀이 제거될것이라고 델리게이트에게 알려준다

func tableView(UITableView, didEndDisplayingHeaderView: UIView, forSection: Int)
// 특정 section의 header가 제거될것이라고 델리게이트에게 알려준다

func tableView(UITableView, didEndDisplayingFooterView: UIView, forSection: Int)
// 특정 section의 footer가 제거될것이라고 델리게이트에게 알려준다

테이블 뷰 focus를 관리하는 메서드

func tableView(UITableView, canFocusRowAt: IndexPath) -> Bool  
// 특정 셀이 focus 가능한지 알려준다

func tableView(UITableView, shouldUpdateFocusIn: UITableViewFocusUpdateContext) -> Bool  
// 특정 focus를 context로 업데이트 가능한지 알려준다

func tableView(UITableView, didUpdateFocusIn: UITableViewFocusUpdateContext,  
with: UIFocusAnimationCoordinator)  
// context에 의해 특정 focus가 업데이트 됐다고 델리게이트에게 알려준다

func indexPathForPreferredFocusedView(in: UITableView) -> IndexPath?  
// 테이블 뷰에서 preferred focus나 default focus되어있는 셀의 index를 가져온다

반응형
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함