본문 바로가기
iOS/iOS

Expandable tableView Cell(셀 확장)

by 패쓰킴 2023. 1. 26.
728x90

셀을 누르면 아래로 상세 내용이 펼쳐지는 UI를 만들 때는

상세 내용을 hidden 시켰다가 셀이 눌리면 보여주는 형식으로 구현하면 된다

 

1. 셀을 눌렀을 때 보여줄 view를 'myView.isHidden = true' 로 만든다.

 

2. 셀이 눌리면 myView의 isHidden 상태를 반전 시켜주고, 

    해당 셀을 reload시켜준다.

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  myView.isHidden = !myView.isHidden
  tableView.reloadRows(at: [IndexPath(row: indexPath.row, section: 0)], with: .automatic)
}

 

3. 셀의 높이를 myView가 hidden 상태일 때와 아닐 때로 나누어 설정해준다.

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  return myView.isHidden ? 86 : 446
}

 

참고:

https://ios-development.tistory.com/1222

 

[iOS - swift] extendable tableView 구현 방법 (동적으로 늘어나는 셀 구현), reloadRows(at:with:)

Extendable tableVeiw 구현 아이디어 셀의 UI는 stackView에 label을 넣고 hidden을 on/off하며 펼쳐지거나 줄어들게끔 구현 데이터 소스 타입에 isDescHidden와 같이 플래그를 넣고, 확장하고 싶은 경우 isDescHidden

ios-development.tistory.com

https://medium.com/@MuralidharanKathiresan/uitableview-with-collapsible-expand-and-collapse-cells-ios-swift-8a1db381000e

 

UITableView with Collapsible (expand and collapse) Cells iOS Swift

Many times we see the use-case like tableview cells should expand and collapse when tapped, let us see one easy implementation for the…

medium.com

https://blog.devgenius.io/easy-way-to-create-an-expandable-uitableviewcell-in-swift-5-a5c72d1361da

 

Expandable UITableViewCell in Swift 5 (Simple Way)

We will see how to create expandable tableview cells without using sections.

blog.devgenius.io

 

728x90

'iOS > iOS' 카테고리의 다른 글

URL Scheme  (0) 2023.01.26
present된 ViewController에 push  (0) 2023.01.26
빌드한 앱의 권한 제어  (0) 2023.01.11
설정앱의 특정 화면으로 이동??  (0) 2023.01.06
CustomView의 super  (0) 2023.01.04

댓글