iOS/iOS SeSAC 2기 TIL

iOS swift] tableView section 이름 붙이기 - titleForHeaderInSection

Developer-Michelle 2022. 8. 7. 14:38

iOS swift] tableView section 이름 붙이기 (섹션마다 title이 있는 tableView) 키워드: titleForHeaderInSection

 

https://calmone.tistory.com/entry/iOS-UIKit-in-Swift-4-section%EC%9C%BC%EB%A1%9C-%EB%82%98%EB%88%84%EC%96%B4%EC%A7%84-UITableView-%EB%A7%8C%EB%93%A4%EA%B8%B0

 

[iOS UIKit in Swift 4] section으로 나누어진 UITableView 만들기

section으로 나누어진 UITableView 만들기 UITableView를 2개의 section으로 나누어 iOS와 AOS의 버전을 나열해봤습니다. section의 index는 0부터 시작하며 0번째 section의 header의 타이틀은 iOS, 1번째는 AOS..

calmone.tistory.com

titleForHeaderInSection에서는 section마다 표현될 title을 정의합니다.
// Returns the title of the section.
        
        
          
              func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
        
        
          
                  return sections[section]
        
        
          
              }

 

https://ksk9820.tistory.com/54

 

[iOS/swift] UITableview Section과 Cell 에 데이터 넣기_우동 자세한 회비내역_210726

이전 페이지의 날짜 정보 다음 페이지에 전달하고, 그 날짜에 대한 자세한 내역을 서버에서 받아오면 클라이언트에 표시하는 기능을 만들어야 한다. 1. UITableView에 항목, 벌금을 내거나/사용한

ksk9820.tistory.com

 

section 마다 헤더 이름을 표시해주고 싶은 경우:

 

var item: [String] = [ ] 

var item = ["미제출", "미흡제출", "지각", "지출"]

 

item은 table의 section에 표시되어야함.

 

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

 return item[section]

}

 

위의 블로그에서 퍼온 이미지. 이런식으로 섹션 이름 붙여야함.

 

----------------------------------------------------------

 

section 을 배열의 index같은 느낌으로 생각하면 될 것 같다.

배열 이름 [section]

항상 이런식으로 쓰네~

 

 

 

https://velog.io/@din0121/Section-Index-Title

 

[Swift] - Section Index Title

연락처 오른쪽에 보면 초성이 있는데 그것을 Section Index Title이라고 함.

velog.io

 

 

아래처럼 switch구문으로 쓸 수도 있음.

 

https://gist.github.com/RNHTTR/23742f370b26c0181a56f552b8575020

 

Determine the title for each section in a UITableView.

Determine the title for each section in a UITableView. - titleForHeaderInSection.swift

gist.github.com