Project 05 - TableView

DaY·2021년 3월 28일
1

iOS

목록 보기
18/52
post-thumbnail

유동적인 Table View의 Cell을 위해 Cell 안의 Constraints를 잘 지정해주는 것이 중요하다.

AutomaticDimension

Cell마다 다른 높이를 적용하기 위해서는 tableView 메소드 중 HeightForRowAtIndexPath를 사용해 임의로 해당 Cell의 높이를 지정해 줄 수 있다.
하지만 같은 Cell을 사용하는 행마다 다른 높이를 지정해주기 위해서는 AutomaticDeimension을 사용해야 한다.

TableView.rowHeight = UITableView.automaticDimension

EstimatedRowHeight

위의 AutomaticDimension 말고도 EstimatedRowHeight가 필요하다.
EstimatedRowHeight는 예상되는 RowHeight 값이다.

// 직접 대입
TableView.estimatedRowHeight = 300

// 또는 메서드 사용
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
    return 300
}

EstimatedRowHeight가 너무 낮으면 테이블 ReloadData시 엉뚱한 곳에 스크롤되는 경우가 발생할 수 있으므로 적절한 값을 설정해주는 것이 중요하다.

0개의 댓글