質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

解決済

1回答

5006閲覧

swift4で画面遷移についてコードのみで行おうと思うのですが、うまく行きません。

you555

総合スコア21

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

0クリップ

投稿2018/10/13 04:07

swift4で画面遷移をコードのみで行いたいのですが、うまくうきません。storyboardは、ViewControllerで作成しています。
エラーの内容は、以下です。

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard (<UIStoryboard: 0x1c4275740>) doesn't contain a view controller with identifier 'CameraSampleController'' *** First throw call stack: (0x182f1ad8c 0x1820d45ec 0x18d4a8fb8 0x1040f38e4 0x1040f3d30 0x18cc8964c 0x18cdaa870 0x18cc8f700 0x18cdc51a8 0x18cd0c9e0 0x18cd01890 0x18cd001d0 0x18d4e1d1c 0x18d4e42c8 0x18d4dd368 0x182ec3404 0x182ec2c2c 0x182ec079c 0x182de0da8 0x184dc6020 0x18ce00758 0x1040f5290 0x182871fc0) libc++abi.dylib: terminating with uncaught exception of type NSException

遷移先のstoryboardの設定は以下のようにしています。

イメージ説明

どうしてもわからないので、誰かご尽力をしていただけないでしょうか。
以下が全体のソースです。

// ViewController

import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. // UIButtonのインスタンスを作成する let button = UIButton(type: UIButtonType.system) // ボタンを押した時に実行するメソッドを指定 button.addTarget(self, action: #selector(buttonEvent(_:)), for: UIControlEvents.touchUpInside) // ラベルを設定する button.setTitle("起動", for: UIControlState.normal) // サイズを決める(自動調整) //button.sizeToFit() // サイズを変更する button.frame = CGRect(x: 0, y: 0, width: 150, height: 50) // 任意の場所に設置する button.layer.position = CGPoint(x: self.view.frame.width/2, y:200) // 文字色を変える button.setTitleColor(UIColor.white, for: UIControlState.normal) // 背景色を変える button.backgroundColor = UIColor(red: 1.0, green: 0, blue: 0, alpha: 1) // 枠の太さを変える button.layer.borderWidth = 1.0 // 枠の色を変える button.layer.borderColor = UIColor(red: 1.0, green: 0, blue: 0, alpha: 1).cgColor // 枠に丸みをつける button.layer.cornerRadius = 25 // 影の濃さを決める button.layer.shadowOpacity = 0.5 // 影のサイズを決める button.layer.shadowOffset = CGSize(width: 2, height: 2) // ボタンが押されたときのラベル //button.setTitle("押された!", for: UIControlState.highlighted) // ボタンが押されたときの文字色 button.setTitleColor(UIColor.red, for: UIControlState.highlighted) // 位置を決める(画面中央) button.center = self.view.center // viewに追加する self.view.addSubview(button) } // ボタンが押された時に呼ばれるメソッド @objc func buttonEvent(_ sender: UIButton) { print("ボタンの情報: (sender)") let storyboard = UIStoryboard(name: "CameraSample", bundle: nil) let sampleCameraView = storyboard.instantiateViewController(withIdentifier: "CameraSampleController") self.present(sampleCameraView, animated: true, completion: nil) } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }

// CameraSampleController

import UIKit class CameraSampleController: UIViewController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Storyboard (<UIStoryboard: 0x1c4275740>) doesn't contain a view controller with identifier 'CameraSampleController''

アプリはNSInvalidArgumentException (不正な引数による例外)により終了しました。
理由:Storyboardに'CameraSampleController'というIDを持つViewControllerはありません。

storyboard.instantiateViewController(withIdentifier: "CameraSampleController")

withIdentifierですから、指定するのはクラス名(CameraSampleController)じゃなくてID(camera-sample)です。

投稿2018/10/13 05:05

編集2018/10/13 05:06
toki_td

総合スコア2850

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問