0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

NavigationControllerからモーダル遷移をする時に出たエラーCould not cast value of type..

Posted at

##遭遇したエラー
Could not cast value of type..

##状況
NavigationControllerにTableViewCellを配置し(LINEのイメージ)基本的な遷移(以下①)はTableViewCellを押すことで行っている。
ある時のみ(具体的には開発者によるアカウント削除)にはモーダル遷移(以下②)を行う。

##原因と対処
segue.identifierによる条件分岐ができておらず、②の遷移の時に①で行うときの値遷移の処理がおこなわれ、クラッシュしていた。

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "cellSegue" {

        let indexPath = self.roomTableView.indexPathForSelectedRow
        let NextVC = segue.destination as! ChatViewController
        NextVC.roomName = self.joinedRoomName[indexPath!.section]!
        NextVC.roomPassword = self.joinedRoomPassword[indexPath!.section]!
        NextVC.password = "\(joinedRoomName[indexPath!.section]!)\(joinedRoomPassword[indexPath!.section]!)"
        } 
        
    }

のようにif segue.identifier == ""を設定することでクラッシュを防ぐことができた。

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?