LoginSignup
1

More than 3 years have passed since last update.

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "xxx" nib but the view outlet was not set.'というエラーがでたとき。

Last updated at Posted at 2020-03-01

概要

イニシャライザでnibを呼び出す時に次のようなエラーが出た。

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "xxxViewController" nib but the view outlet was not set.'
init()
init() {
        super.init(nibName: UserSearchViewController.className, bundle: nil)
    }

loadViewで呼び出した時はこのエラーがでなかった。

loadView()
override func loadView() {
        guard let view = UINib(nibName: "UserSearchViewController", bundle: nil).instantiate(withOwner: self, options: nil).first as? UIView else { return }
        self.view = view
    }

結論

貼り付けた画像_2020_03_01_13_57.png

  • ①InspectorのFile`sOwnerにCustomClassをセットする。
  • ②Placeholders>File`s OwnerからViewにOutletで接続する。(※画像を参考)

これでエラーがでなくなりました。

コードで実装していたときは、Ownerを指定したのに、init()の時はnibをロードするだけでOwnerを指定していたなかったのが原因かと思われます。

参考

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1