2021.04.12 TIL ⬇️

Jackson·2021년 4월 12일
0

TIL(Today I Learned)

목록 보기
16/42

비도 오고 그래서
니 생각이 났어
생각이 나서 그래서
그랬던 거지
별 의미 없지...

기능하나를 위해서 알아야할게 계속 나오네... 🤮

벌써 일수로만 3일째 Drag Drop을 하고 있다. 그래서 해결했냐고 하면 내일까지는 해야 해결이 될 것 같다. 같은 팀원에게도 참 미안하다. 해결하려니 알아야 할게 계속 생긴게 문제였다.

Table 내에서 카드 이동

일단 Table내에서는 반은 구현이 완료되었다. 이유는 잘 모르겠지만 위 카드를 밑 카드로 옮기는 과정에서 애니메이션이 적절하진 않았다.

func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {

        tableView.moveSection(sourceIndexPath.section, toSection: destinationIndexPath.section)
        
    }

이 함수만 쓰면 앱 크래쉬가 계속 나서 해결하는 과정에서 proposedDestinationIndexPath 를 이용해 원하는 곳으로 이동시키게 할 수 있었다.

func tableView(_ tableView: UITableView, targetIndexPathForMoveFromRowAt sourceIndexPath: IndexPath, toProposedIndexPath proposedDestinationIndexPath: IndexPath) -> IndexPath {
        
        //앱 설계상 1 Section 1 Row이기에 row가 1이면 0으로 바꾸어 앱 크래쉬를 막아준다.
        if proposedDestinationIndexPath.row != 0 {
            let proposedIndexPath = IndexPath(row: 0, section: proposedDestinationIndexPath.section)
        
            return proposedIndexPath
        }
        
        return proposedDestinationIndexPath
    }

Table 간 카드 이동

이 부분을 구현하기 위해 정말 많은 삽질을 했다. 늦게까지 하는 와중에 이제서야 하나를 이해했는데 그 부분은 Drag를 할 때 저장할 item을 대게 data로 보낸다.

클래스는 data를 처리하기 위해서 Encoding이 필요하다는 점을 알았다.
그래서 알게된 Codable 알고 보니 후에 작업해야할 아카이빙이 이것과 연관되는것 같다. EncodingDecoding에 대한 예제를 보고 이해가 안되도 따라치며 먼저 구현해보니 Drop함수에서 해당 카드의 정보를 알 수 있었다. 무야호!!!

for item in coordinator.items {
    item.dragItem.itemProvider.loadObject(ofClass: Card.self, completionHandler: { (card, error) in
        if let card = card as? Card {                                              print("card",card.content,card.title,card.writer)
                    
                    //여기서 추가 작업이 들어간다.
        }
})

결론

  • 아직 구현해야 할게 많지만 오늘은 여기까지가 최선인것같다. 졸리다..
  • 내일 짝한테 궁금한것을 질문해야겠다.

0개의 댓글