tableView 는 pinEdge 처럼 가득(?)차 있다. tableView의 cell 갯수는 num
변수로 원하는 만큼 설정 할 수 있다.
처음에 깔릴때 tableView의 size는 delegate를 이용해 frame size를 넘김다. (초기 크기는 viewDidLayoutSubviews
에서 넘긴다.)
cell
의 크기가 expand 될 땐 frame 값을 어떻게 넘겨주지?try1) didSelectRow
에서 tableView.contentSize.height
를 delegate
로 넘겨준다?!
→ FAIL : tableView.contentSize.height
가 바로바로 업데이트가 안된다.
이 말은 뭔말이냐면 한 turn 느리게 update가 된다는 말이다. 동기가 안된다.
try2) observer 달기
var tableViewHeightSizeObserver: CGFloat = 0.0 {
willSet {
print("will set \(newValue)// \(tableView.contentSize.height)")
}
didSet {
if tableViewHeightSizeObserver > oldValue {
print("did set \(oldValue)")
tableView.frame = CGRect(x: 0, y: 0,
width: UIScreen.main.bounds.width - 32,
height: tableViewHeightSizeObserver)
delegate?.containerHeight(height: tableViewHeightSizeObserver)
}
}
}
→ tableView.frame
update 해주고 didSet
조건 만족 시키면 delegate
로 넘겨준다.
(조건은 이전 값(oldValue
) 보다 크다면 update 해줘라 ~)
아 그리고 didSelectRow
에서
Select와 동시에 tableView의 frame을 알아야 한다.
동시에 ?! 하면 뭐가 떠오르는가 ?
GCD !
나의 GCD에 대한 주워들은 내용으로는 view에 관한건 main으로 알고 있다 .. 사실 그냥 관습상 쓴건데... 공부해야겠다.
그뭐냐 그래서 Observer에 tableView의 contentSize를 넘겨주면 된다.
beginUpdate와 endUpdate가 곧(?) Deprecated된다고 한다.
그래서 performBatch...쓰라는데 잘 모르겠다.