[ iOS 기초개념 ] UITableView 메서드 정리

Woong·2022년 5월 10일
0

UITableView에서 쓰여지는 메서드를 정리해보자!

1. 테이블의 섹션 개수를 묻는 메서드 (보통은 1개를 지정한다)

override func numberOfSections(in tableView: UITableView) -> Int {
	return 
}

위에 return 1 을주는게 통상적이지만 return 3 을주게되면 아래와 같은 값이 표기가된다.

2. 각 섹션에 표시할 행의 개수(limit)를 묻는 메서드

override func tableView(_ tableView: UITableView, numberOfRowsInSection section : Int) -> Int{
	return 
}

return 뒤에 보통 데이터의 배열이 존재하는경우 return dataArray.count 라고 처리를 하곤 함. (*실습에선 그렇게 많이했어.... ㅠㅠ)

3. 셀의구성 : 특정 인덱스 Row의 Cell에 대한 정보를 넣어 Cell을 반환하는 메서드

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
	let cell tableView.dequeueReusableCell(withIdentifier: "표시할셀 이름", for: indexPath) 
}


Main - TableViewController - cell의 identifier를 "naeCell"로 설정해주면 위에 "표시할셀 이름" = "naeCell" 이라고 표기해주면 되는거당

4. 특정 섹션의 헤더 타이틀을 묻는 메서드

override func talbeView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String?

이건 사용안해봤는데 나중에 꺼내먹어봐야겠다.(아래와 비슷)

5. 특정 섹션의 풋터 타이틀을 묻는 메서드

override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String?

이건 사용안해봤는데 나중에 꺼내먹어봐야겠다.(위와비슷)

6. 특정위치의 행이 편집 가능한지 묻는 메서드

override func tableView(_ tableView: UITableView, canEditRowAt indexPath) -> Bool

나는 테이블뷰에서 안써본게 참 많구나..

7. 특정위치의 행을 재정렬 할 수 있는지 묻는 메서드

override func tableView(_ tableView: UITableView, canMoveRowAt indexPatt: IndexPath) -> Bool

너두..

8. 테이블 뷰 섹션 인덱스 타이틀을 묻는 메서드

override func sectionIndexTitles(for tableView: UITableView) -> String?

9. 인덱스에 해당하는 섹션을 알려주는 메서드

override func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int

10. 스와이프 모드, 편집 모드에서 버튼을 선택하면 호출 되는 메서드

override func tableView(_ tableView: UITableView, commit edittingStyle: UITableViewCell.EditingStyle, forRowAt indexPath : IndexPath){
여기부분에 code를 커밋해줘야한다
}

지난번 교육에서는 이 메서드에서 Edit을 통해 삭제했을 때, 처리과정을 정의해줬었다!

11. Edit 눌렀을 때, Delete의 이름을 바꿔주는 메서드

override func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
return "바꿀이름"
}

바꿀이름을 "삭제"로 바꿔주면 삭제로 나오게 된다 ㅎㅎ

12. 행이 다른 위치로 이동되면 어디에서 어디로 이동했는지 알려주는 메서드

override func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath, to destinationIndexPath: IndexPath)

빨리써보고알려줄게

profile
https://github.com/iOS-Woong

0개의 댓글