[iOS/Swift] UITableViewCell 겹침 현상

chaentopia·2023년 6월 7일
0
post-thumbnail

UITableView를 만들던 중 numberOfRowsInSection 불러준 개수대로 cell이 불러와지지 않는 현상을 마주했다.

extension HomeView: UITableViewDelegate, UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 2
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard let cell = tableView.dequeueReusableCell(withIdentifier: HomeTableViewCell.identifier, for: indexPath) as? HomeTableViewCell else { return UITableViewCell() }
        return cell
    }
}

분명 return 2를 해줬는데..

하나만 보인다..
rowHeight도 제대로 줬음에도 불구하고.. 무엇이 문제인지 hierarchy를 보았는데

엥...... cell이 전부 겹쳐있었다 혹시나 해서 셀 개수를 더 늘려봤더니

오.. 확실해졌다. 확인해보니
 self.snp.makeConstraints{
            $0.height.equalTo(74.adjusted)
            $0.width.equalTo(UIScreen.main.bounds.width)
        }

cell의 레이아웃을 잡을 때 이렇게 잡은 것 때문에 그랬다..
이 부분을 삭제하니

성공했다!!!! 이유는 모르겠다... 이유를 찾으면 추가하겠다...
profile
the pale blue dot

0개의 댓글