특정 Static Cell 제거

4394 단어 SwiftiOS

Static Cels에 정의된 TableView에서 녹색 cell 제거



셀의 하이라이트를 0으로 설정합니다.

    override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if indexPath.row == 4 {
            return 0
        }
        return super.tableView(tableView, heightForRowAt: indexPath)
    }
하이라이트를 0으로만 설정했기 때문에 스토리보드에 녹색 셀은 계속 저장됩니다.징그럽다.

cell 불러오기 건너뛰기

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return super.tableView(tableView, numberOfRowsInSection: section) - 1
    }

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.row > 3 {
            return super.tableView(tableView, cellForRowAt: IndexPath(row: indexPath.row + 1, section: 0))
        }
        return super.tableView(tableView, cellForRowAt: indexPath)
    }
상기 방법보다 코드량이 많지만 쓸모없는cell을 불러오는 비용이 줄어든다.

좋은 웹페이지 즐겨찾기