Could not cast value of type 'UIViewController'の対処
自分がエラーを起こして、画面遷移ができなかった時の原因と対処を記録として残します。
コードはこんな感じでした。
@IBAction func tappedDontHaveAccountBottun(_ sender: Any) {
let storyBoard = UIStoryboard(name: "Login", bundle: nil)
let homeViewController = storyBoard.instantiateViewController(identifier: "LoginViewController") as! LoginViewController
navigationController?.pushViewController(homeViewController, animated: true)
}
エラーの原因
このコードでのidentifierのところがエラーになっていました。
エラーから自分は単純に,Custom class, Module, Storyboard IDなどがうち間違っているのかと推測
エラーの対処
なので、コードとCustom class, Module, Storyboard IDの相違がないように、コピペして再リロードすると改善しました。
この使っているメソッドは、instantiateViewController(identifier:)です。
つまり、このメソッドは識別されたidentifierを持つViewControllerを作成し、Storyboardでのデータを持ってインスタンスを初期化するメソッドなので、homeViewControllerを、インスタンスを初期化したLoginViewControllerとして作成しているのだと思います。(初心者なりの理解ですので間違っているかもしれません。申し訳ないです、、、)