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. } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。