not good but great

プログラミング、アート、映画・本の感想について書きます。

エラー"this class is not key value coding-compliant for the key tapView"の解決法

こちらの本を見てObjective-Cを学習中です。

this class is not key value coding-compliant for the key tapView

Flipsideシーンの設定値をMainシーンに渡すところでこんなエラーが出ました。

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tapView.'

コードは変数名以外コピペだったので、間違いがわかりませんでした。tapViewと書いてあるので、そこがおかしいのかと思い調査。

storyboardから紐付けを再度行う

- (IBAction)tapView:(UITapGestureRecognizer *)sender {
    [self.view endEditing:YES];
}

storyboardから紐付けをしたときに出来た関数を見逃していて、自分で改めて同じ名前の上の関数を宣言していたことが原因でした。最初に出来た関数を消したので、うまく動くと思っていました。storyboardのtapViewをやり直して、紐付けも再度行うと、実行できました。

自分で書いてもOKという話を聞いたので、もしかしたら単なるスペルミスだったのかもしれません・・・。xcodeでエラーが出ていなかったし、UITapGestureRecognizerの指定も正しかったとは思います・・。