Skip to content

Conversation

@OpenBible3438
Copy link

JSON

  • Bundle.main.path 글을 참고하여 Codable 구조체도 quicktype에서 JSON 파일 형식대로 만들어준 형태로 사용했습니다.

TableViewCell 동적 높이 조절

didSet

  • Work Info를 담은 Label을 Hide / Show 하기 위해 �didSet으로 Label.isHidden = true 설정했습니다.
  • "Select For More Info >" 표시하는 Label에 대한 isHidden 설정은 didSet에서 굳이 하지 않아도 되지만 같이 적용해주었습니다.
class WorkListTableViewCell: UITableViewCell {
    @IBOutlet weak var workImageView: UIImageView!
    @IBOutlet weak var workNameLabel: UILabel!
    @IBOutlet weak var workInfoLabel: UILabel! {
        didSet {
            workInfoLabel.isHidden = true
        }
    }
    @IBOutlet weak var selectInfoLabel: UILabel! {
        didSet {
            selectInfoLabel.isHidden = false
        }
    }
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    let cell = tableView.cellForRow(at: indexPath) as! WorkListTableViewCell
    if cell.workInfoLabel.isHidden {
        cell.workInfoLabel.isHidden = !cell.workInfoLabel.isHidden
        cell.selectInfoLabel.isHidden = !cell.selectInfoLabel.isHidden
    } else {
        cell.workInfoLabel.isHidden = !cell.workInfoLabel.isHidden
        cell.selectInfoLabel.isHidden = !cell.selectInfoLabel.isHidden
    }
    tableView.beginUpdates()
    tableView.endUpdates()
    tableView.scrollToRow(at: indexPath, at: .top, animated: true)
}

Notification

  • 저 또한 레퍼런스 코드가 무슨 의미로 작성된건지 찾아 헤맸습니다 ㅠㅠㅎㅎㅎ
  • NotificationCenter.default.addObserver를 다른 방식으로 변화를 감지해볼까 했지만 이 프로젝트에서는 별다른 변화를 알릴 수 있는 게 딱히 떠오르지 않아서 레퍼런스 코드 그대로 진행했습니다.
// Notification
 NotificationCenter.default.addObserver(forName: UIContentSizeCategory.didChangeNotification, object: .none, queue: OperationQueue.main) { [weak self] _ in
      self?.workListTableView.reloadData()
 }

// Label
cell.workInfoLabel.font = UIFont.preferredFont(forTextStyle: .body)

느낀점

  • 레퍼런스 코드는 UI 형태와 진행 방향 분석 정도만 처음 참고하고 만들기 시작해서 Bio와 work Info 부분을 처음에는 TextView로 만들었습니다. (현재는 Label로 변경)
  • TextView의 특성상 Text 선택, 수정 등의 기능이 있어서 Cell에 적용했을 때 didSelectRowAt이 적용 안 되었습니다. 이러한 사용자와의 상호작용을 비활성화하는 코드를 작성해서 Cell 선택이 가능하도록 했습니다.
cell.artistBioTextView.isUserInteractionEnabled = false
  • Notification을 구현할 때도 설정에 따라 변화될 Label에 대해서도 코드를 작성해주어야 됐습니다.
  • 화면에 보이는 부분만을 생각하고 개발을 진행했을 때 생기는 문제를 풀어가면서 해당 요소의 특성을 좀 더 알 수 있었던 것 같습니다.

@AKAPUCH
Copy link
Contributor

AKAPUCH commented Jun 25, 2023

수고하셨습니다!
Codable 모델에 isHidden과 비슷한 프로퍼티를 추가하느라 고생했는데, didSet을 활용하는 방법이 있었네요..
notification은 텍스트 크기 설정값 가져오기 예제를 참고하시면 좋을 것 같습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants