LoginSignup
21
9

More than 3 years have passed since last update.

iOSアプリのunrecognized selector sent to instanceエラーについて

Last updated at Posted at 2018-08-03

iOSアプリのunrecognized selector sent to instance エラーについて

はじめに

ダイアログを表示する画面を作成していた時にunrecognized selector sent to instanceのエラーが起こり四苦八苦したのでメモとして残します。

TL;DR

結局StoryBoardに設定するCustom Classのクラスが違うクラスを指定していたことが原因というオチ。。。
スクリーンショット 2018-08-03 13.30.26.png

経緯

こんな感じでViewControllerを呼び出してダイアログ表示をしようとしていたが、タイトルのエラーが起こりうまく行かなかった。クラスが原因かと思い色々見直したがアクセスはできるし、原因が謎だった(そもそも筆者がObjective-C、iOS開発あまり知らない人でてんやわんや)

// 指定のViewControllerインスタンスを作成、その際に
HogeDialogViewController *vc = [
    [UIStoryboard storyboardWithName:@"HogeDialogViewController" bundle:nil] 
     instantiateViewControllerWithIdentifier:@"HogeDialogViewController"];
// Dictionary型を作成し、Entityを作成する
NSDictionary *responseObject = [NSDictionary dictionaryWithObjectsAndKeys:
        @"id", @1111,
        nil];
HogeData *hogeData = [[HogeData alloc] initWithDictionary:responseObject];
vc.hogeData = hogeData;
// Dialog表示
[vc show];

StoryBoardを見直す

コードは問題ないと考え、StoryBoardを見直したところ、Custom Classのクラス名が違うクラスを指定していたからViewControllerにインスタンスをセットできないよと怒られていたようです。

所感

よくよく考えてみたら存在しないStoryBoardを指定してそのインスタンスの存在しないフィールドにアクセスしようとしてたんだから、そりゃ怒られるよねっていう話。iOS開発大変だなぁと思った。ていうかObjective-cじゃなくてSwift触りてえ。

参考情報

21
9
0

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
21
9