관리 메뉴

김종권의 iOS 앱 개발 알아가기

[iOS - swift] storyboard 에러- 1. NSUnknownKeyException, this class is not key value coding-compliant for the key // 2. Unexpectedly found nil while implicitly unwrapping an Optional value 본문

iOS 응용 (swift)

[iOS - swift] storyboard 에러- 1. NSUnknownKeyException, this class is not key value coding-compliant for the key // 2. Unexpectedly found nil while implicitly unwrapping an Optional value

jake-kim 2021. 5. 25. 00:41

stroyboard 버그

  • *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x105c22490> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key webView.'

원인

  • .swift파일에서 storyboard와 연결되어 있던 @IBoutlet파일이 삭제되어 storyboard에만 존재하는 경우
  • Inspector창에서 Inherit Moudle From Target이 체크되지 않은 경우

  • UIView를 커스텀한것이 아닌, UITableViewCell과 같은것에서 시도한 경우
    • UITableViewCell는 Cocoa Touch Class를 사용하여 생성해야 에러가 나지 않고, 아래처럼 생성하면 에러 발생

주의) Cell을 사용한다면, register() 시에 nib 파일을 넣어야함

Cell을 사용하는 곳에서 에러

  • 에러: Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
  • 위와같이 뜰 경우, storyboad에 있는 Cell의 inspector에 클래스 이름을 넣었지만, 코드에도 register하여 중복으로 등록한 경우 -> register 코드 삭제 시 해결
  • 이유: storyboard안의 tableVIew나 CollectionView에 내장되어 있는 Cell에 class명을 등록해놓으면, 이미 cell이 해당 뷰에 내장되어 있다는 의미이므로 register를 호출하면 중복 등록으로 에러 발생
Comments