他の質問サイトでもタイトルのような質問はいくつもあったのですが、xcode8でSwift3.0の画面遷移はなかなか見つかりませんでしたので質問させていただきます。
質問内容をまとめると、AAAというUIViewControllerからBBBというUIViewControllerに画面遷移する際にAAA内のパラメータをBBBのパラメータに渡したいです。
AAA(UIViewController)のIdentityのStoryBoard IDがaaa。
BBB(UIViewController)のIdentityのStoryBoard IDがbbb。
以下のコードを書きAAA上のボタン(aaabtn)を押したとき「libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 」というエラーが出ます。解決策の提案をよろしくお願いします。
Swift
1// AAA.swift 2 3import UIKit 4 5class AAA: UIViewController{ 6 7 @IBAction func aaabtn(_ sender: Any) { 8 9 print("aaabtnが押されました") 10 performSegue(withIdentifier: "bbb",sender: nil) 11 } 12 13 override func viewDidLoad() { 14 super.viewDidLoad() 15 print("AAAが読まれました") 16 } 17 18 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 19 if segue.identifier == "bbb" { 20 let secondViewController = segue.destination as! BBB 21 secondViewController.parameter = 1 22 } 23 } 24 25 override func didReceiveMemoryWarning() { 26 super.didReceiveMemoryWarning() 27 // Dispose of any resources that can be recreated. 28 } 29}
swift
1//BBB.swift 2 3import UIKit 4 5class BBB: UIViewController{ 6 7 @IBOutlet weak var label: UILabel! 8 var parameter:Int = 0 9 override func viewDidLoad() { 10 super.viewDidLoad() 11 12 print("BBBが読まれました") 13 print(parameter) 14 } 15 16 override func didReceiveMemoryWarning() { 17 super.didReceiveMemoryWarning() 18 // Dispose of any resources that can be recreated. 19 } 20}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/12/31 11:29
2016/12/31 11:37 編集
2016/12/31 12:04
2016/12/31 12:17
2016/12/31 12:38
2016/12/31 12:43
2016/12/31 12:48
2016/12/31 12:53
2016/12/31 12:59 編集
2016/12/31 13:05
2016/12/31 13:08
2016/12/31 13:12
2016/12/31 13:17
2016/12/31 13:19
2016/12/31 13:26
2016/12/31 13:40
2016/12/31 13:47 編集