고도고도
🍎🍏
고도고도
전체 방문자
13,424
오늘
31
어제
64
  • 분류 전체보기 (170)
    • 🔨 프로젝트 (0)
      • TP 1 (0)
      • WhiteHCCTV (0)
      • FootPrint (0)
    • 💻 개발 (61)
      • iOS (28)
      • Android (6)
      • Kotlin (4)
      • Flutter (9)
      • Node.js (5)
      • Architecture (1)
      • 오늘의 삽질 (7)
      • 에러와의 동침 (1)
    • ✏️ 알고리즘 (6)
      • Graph (6)
      • String (0)
      • Sort (0)
    • ✍️ 코테 준비 (44)
      • Math (1)
      • Implementation (3)
      • String (3)
      • Brute Force (5)
      • Back Tracking (7)
      • Greedy (0)
      • Dynamic Programming (13)
      • Binary Search (1)
      • DFS, BFS (5)
      • Shortest Path (2)
      • Two Pointer (4)
      • MST (0)
    • 📚 CS (6)
      • Operating System (6)
    • ⛹️ 라이프 (53)
      • 2020 겨울방학 모칵코(팀) (13)
      • 2020 겨울방학 모각코(개인) (13)
      • 2021 여름방학 모칵코(팀) (8)
      • 2021 여름방학 모각코(개인) (7)
      • 코딩 테스트 (1)
      • 회고 (10)

블로그 메뉴

  • 홈
  • 깃허브
  • 링크드인

공지사항

인기 글

  • [NCSOFT] 2022 엔씨소프트 썸머 인턴 후기 - 1⋯
    2022.08.10
    [NCSOFT] 2022 엔씨소프트 썸머 인턴 후기 - 1⋯
  • [Flutter] SingleChildScrollView,⋯
    2021.08.18
    [Flutter] SingleChildScrollView,⋯
  • [iOS / SwiftUI] MapKit, 실시간으로 도로⋯
    2022.12.20
    [iOS / SwiftUI] MapKit, 실시간으로 도로⋯
  • [Android] 백그라운드에서 소켓 통신으로 이벤트 수신⋯
    2022.06.08
    [Android] 백그라운드에서 소켓 통신으로 이벤트 수신⋯
  • [iOS / SwiftUI] OnAppear, OnDisa⋯
    2022.12.01
    [iOS / SwiftUI] OnAppear, OnDisa⋯

최근 댓글

  • https://developer.apple.com/docu⋯
    고도고도
  • 게시글 잘 보았습니다. 혹시 주소에서 구를 가지고 오시는⋯
    나그네
  • 혹시 댓글이 안보이는데 .. y2e010924@naver.⋯
    eun
  • 글 솜씨가 뛰어나시네요! 좋은 글 잘 보고 갑니다 다음에도⋯
    alpha-traveler
  • NC......가슴이...웅장해집니다.......🤯
    이상한핑구 🐧

최근 글

  • [Architecture] MVVM + Clean Arch⋯
    2023.01.07
    [Architecture] MVVM + Clean Arch⋯
  • [iOS / SwiftUI] MapKit, 실시간으로 도로⋯
    2022.12.20
    [iOS / SwiftUI] MapKit, 실시간으로 도로⋯
  • [iOS / SwiftUI] OnAppear, OnDisa⋯
    2022.12.01
    [iOS / SwiftUI] OnAppear, OnDisa⋯
  • [에러와의 동침] 22년 11월 4주차
    2022.11.28
    [에러와의 동침] 22년 11월 4주차
  • [iOS / SwiftUI] 스크롤, 무한으로 즐겨요~ (⋯
    2022.11.28
    [iOS / SwiftUI] 스크롤, 무한으로 즐겨요~ (⋯

티스토리

hELLO · Designed By 정상우.
고도고도

🍎🍏

[iOS / Swift] Exception NSException * "-[UIView setText:]: unrecognized selector sent to instance
💻 개발/오늘의 삽질

[iOS / Swift] Exception NSException * "-[UIView setText:]: unrecognized selector sent to instance

2022. 9. 7. 16:08

Delegate로 특정 Cell을 클릭했을 때 상세 정보 페이지로 이동하도록 구현했다.

extension ViewController : UICollectionViewDelegate {
    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        guard let viewController = self.storyboard?.instantiateViewController(identifier: "DiaryDetailViewController") as? DiaryDetailViewController else { return }
        
        let diary = self.diaryList[indexPath.row]
        viewController.diary = diary
        viewController.indexPath = indexPath
        
        self.navigationController?.pushViewController(viewController, animated: false)
    }
}

 

상세 정보 페이지인 DiaryDetailViewController에서는 전달받은 diary 객체를 가지고 View를 초기화한다.

//
//  DiartyDetailViewController.swift
//  Basic_05
//
//  Created by 고도 on 2022/09/06.
//

import UIKit

class DiaryDetailViewController: UIViewController {
    
    @IBOutlet weak var titleLabel: UILabel!
    @IBOutlet weak var contentsTextView : UITextView!
    @IBOutlet weak var dateLabel: UILabel!
    
    var diary : Diary?
    var indexPath : IndexPath?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.configureView()
    }
    
    private func configureView() {
        guard let diary = self.diary else { return }
        self.titleLabel.text = diary.title
        self.contentsTextView.text = diary.contents
        self.dateLabel.text = self.dateToString(date: diary.date)
    }
    
    private func dateToString(date : Date) -> String {
        let formatter = DateFormatter()
        formatter.dateFormat = "yy년 MM월 dd일(EEEEE)"
        formatter.locale = Locale(identifier: "ko_KR")
        return formatter.string(from: date)
    }
}

 

이후 빌드를 진행했는데 Cell을 클릭하면 아래와 같은 오류가 발생하며 앱이 중지됐다.

Exception NSException * "-[UIView setText:]: unrecognized selector sent to instance 0x13110b480" 0x0000000283b5d920

 

Outlet변수와 View가 제대로 연결되어 있지 않다는 생각에 스토리보드를 살펴봤다. Outlet변수에 마우스를 갖다놓으면 스토리보드 상에서 연결된 View에 대한 정보를 확인할 수 있는데 titleLabel은 UILabel이 아닌 UIView와 연결되어 있는 것을 발견할 수 있었다.

 

contentsTextView
dateLabel

 

titleLabel의 기존 연결을 제거하고정상적으로 연결해주었다.

 

titleLabel

 

 

저작자표시 비영리 변경금지

'💻 개발 > 오늘의 삽질' 카테고리의 다른 글

[iOS / Swift] URL Encoding = nil...? (URL 인코딩이 되지 않을 때)  (1) 2022.09.22
[iOS / Swift] unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard  (0) 2022.08.21
[Android / Gradle] mockup1/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: AAPT: error: failed to read PNG signature: file does not start with PNG signature.  (0) 2022.08.13
[Android / Gradle] The current Gradle version is not compatible with the Kotlin Gradle plugin  (0) 2022.08.09
[Android / Kotlin] Failed to call observer method  (0) 2022.03.30
    '💻 개발/오늘의 삽질' 카테고리의 다른 글
    • [iOS / Swift] URL Encoding = nil...? (URL 인코딩이 되지 않을 때)
    • [iOS / Swift] unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard
    • [Android / Gradle] mockup1/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: AAPT: error: failed to read PNG signature: file does not start with PNG signature.
    • [Android / Gradle] The current Gradle version is not compatible with the Kotlin Gradle plugin
    고도고도
    고도고도
    iOS 꿀잼
    댓글쓰기
    [iOS / Swift] URL Encoding = nil...? (URL 인코딩이 되지 않을 때)
    다음 글
    [iOS / Swift] URL Encoding = nil...? (URL 인코딩이 되지 않을 때)
    [iOS / Swift] unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard
    이전 글
    [iOS / Swift] unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard

    티스토리툴바