콜렉션 뷰에서 선택된 셀만 리로드하기

조회수 590회

안녕하세요. 콜렉션 뷰를 활용해서 ios 앱을 만들고 있습니다.

각 cell 마다 저장된 시간값이 있고 cell을 터치하면 독자적으로 카운트다운이 되는 방식입니다.

타이머 기능은 구현했는데 cell의 텍스트를 초마다 업데이트 하는 기능에서 갈피를 못잡고 있습니다.

타이머를 클래스로 구현한 이유는 cell에 입력된 시간데이터를 받아와야하기 때문인데요.

아래 코드 보시고 가이드 부탁드립니다. ㅠㅠ

 func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        //let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "RecipeListCell", for: indexPath)
        let item = recipeList.item[indexPath.row]

        let cellTimer = TimerControl()
        cellTimer.second = item.time
        cellTimer.timerRun()

        configureText(for: cell, with: item)
       //collectionView.reloadItems(at: indexPath.row)

    }

    class TimerControl {

        var timer = Timer()
        var second: Int = 0

        func timerRun() {
            timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(countDown), userInfo: nil, repeats: true)
        }

        @objc func countDown() {
            //let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "RecipeListCell", for: indexPath)

            if second <= 1 {
                timer.invalidate()
            } else {
                second -= 1

            }
        }

    }
  • (•́ ✖ •̀)
    알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)