2017-11-09 2 views
0

세부 단추를 누를 때 세부 정보가 tableView의 모든 셀로 밀어 넣어 지도록하는 중입니다. 지금까지 테이블 뷰의 보이는 셀을 반복하면서이 물마루를 얻었습니다. 각 셀에는 애니메이션으로 슬라이드하는 화면 밖의 세부 레이블이 있습니다. 이는 모습입니다 : 내가 볼을 반복하고 있기 때문에 상세 버튼을 꾸르의 After detail button pressed 테이블 뷰의 모든 셀에 세부 정보 표시

를 누른 후 상세 버튼

Before Detail Button Pressed

  • 프레스드

    • 하기 전에 세포, 하단에있는 세포는 세부 사항을 때 scr을 세부 단추를 누른 후 olling. 나는 스크린에 보이지 않는 세포가 기억에 있지 않다는 사실을 알고 있지만 이것에 대한 또 다른 접근법이있을 수 있습니까? 여기에 편집

      사용자 프레스 "자세히"버튼을

      let animationDuration = 0.4 
          for cell in myTableView.visibleCells { 
           let cell = cell as! MainCell 
      
           if !detailView { 
            sender.tintColor = UIColor.gray 
            detailView = true 
      
            UIView.animate(withDuration: animationDuration, animations: ({ 
             cell.noteLbl.center.x = cell.noteLbl.center.x + 100 
            })) 
            UIView.animate(withDuration: animationDuration, animations: ({ 
             cell.accessoryLbl.center.x = cell.accessoryLbl.center.x + 100 
            })) 
            UIView.animate(withDuration: animationDuration, animations: ({ 
             cell.timeLbl.center.x = cell.timeLbl.center.x + 100 
            })) 
           } else { 
            detailView = false 
            sender.tintColor = UIColor.white 
      
            UIView.animate(withDuration: animationDuration, animations: ({ 
             cell.noteLbl.center.x = cell.noteLbl.center.x - 100 
            })) 
            UIView.animate(withDuration: animationDuration, animations: ({ 
             cell.accessoryLbl.center.x = cell.accessoryLbl.center.x - 100 
            })) 
            UIView.animate(withDuration: animationDuration, animations: ({ 
             cell.timeLbl.center.x = cell.timeLbl.center.x - 100 
            })) 
           } 
      
          } 
      

      코드가 cellForRowAt에 대한

      func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
          let cell = tableView.dequeueReusableCell(withIdentifier: "MainCell") as! MainCell 
          let shiftForRow = shifts[indexPath.section][indexPath.row] 
      
          cell.noteLbl.text = shiftForRow.note 
          cell.dateLbl.text = shiftForRow.date 
          cell.accessoryLbl.text = calcTotalHours(STField: shiftForRow.startingTime!, ETField: shiftForRow.endingTime!, lunchTime: shiftForRow.lunchTime!) 
          cell.timeLbl.text = shiftForRow.startingTime! + " - " + shiftForRow.endingTime! 
      
          return cell 
      } 
      
+0

저는 두 스크린 샷 사이에 어떤 차이점도 보이지 않으며 "모든 셀"이 의미하는 것조차 명확하지 않습니다. – matt

+0

@matt 두 스크린 샷이 표시되도록 게시물을 업데이트했습니다 (제안 해 주셔서 감사합니다). 두 번째 스크린 샷의 셀에는 왼쪽에있는 세부 정보가 있습니다. 모든 셀에서 버튼을 누르면 모든 셀이 아래로 스크롤 할 때 나타나는 세부 사항을 표시해야한다는 것을 의미합니다. –

+0

관련 코드를 포함하려면 질문을 편집해야합니다. 그러나 현재 'cellForRowAt'를 제대로 구현하지 않았기 때문에 현재 모드를 기반으로 적절한 셀 세부 정보가 표시됩니다. – rmaddy

답변

0

당신이 테이블보기를 스크롤 할 때 (그리고 처음에 표시 될 때 실행되는 코드입니다), 표시해야하는 각 셀에 대해 cellForRowAt 메서드가 호출됩니다.

cellForRowAt은 세부 버튼을 한번도 누르지 않은 것처럼 세포를 "정상적인"레이아웃으로 표시합니다. cellForRowAt 메서드를 업데이트해야 세부 사항을 표시할지 여부를 기반으로 셀을 구성 할 수 있습니다.

세부 정보가 현재 표시되는지 여부를 추적하는 플래그가 필요할 수 있습니다. 눌려진 세부 단추를 기반으로 해당 플래그를 토글합니다.

그런 다음 해당 플래그의 상태에 따라 cellForRowAt 메서드는 셀을 적절하게 설정해야합니다.

관련 문제