123importUIKit45// 遷移元VC6classViewController:UIViewController{78overridefuncviewDidLoad(){9super.viewDidLoad()10// Do any additional setup after loading the view, typically from a nib.11}121314// ボタンタップしてタグを取得、遷移する15@IBActionfunctap(_ sender:UIButton){1617let tagNumber = sender.tag
1819// タグをsenderでprepareに送る20performSegue(withIdentifier:"go2ndVC", sender: tagNumber)21}2223overridefuncprepare(for segue:UIStoryboardSegue, sender:Any?){2425if segue.identifier =="go2ndVC"{26// 遷移先VCを取得して27iflet secondVC = segue.destination as?SecondViewController{28//遷移先VCのプロパティにアクセス、senderで送られてきたタグをIntに変換して渡す29 secondVC.tappedBtnTag = sender as?Int30}31}32}33}343536// 遷移先のVC37classSecondViewController:UIViewController{3839// ここにタップされたボタンのタグが送られてくる40var tappedBtnTag:Int?414243overridefuncviewDidLoad(){44super.viewDidLoad()45// Do any additional setup after loading the view, typically from a nib.4647// 取り合えすプリント、値が渡ってきていなければnil48print("### tappedBtnTag:", tappedBtnTag asAny)4950}51}52
ありがとうございます。このようにして使っていくのですね。
ですが実行したところ、printしたものにはnilが表示されてしまいました。
### tappedBtnTag: Optional(1)
### tappedBtnTag: nil
2018-12-01 22:24:54.212246+0900 challenge[14229:301206] Warning: Attempt to present <challenge.ViewController2: 0x7fe443c31510> on <challenge.ViewController: 0x7fe443d17ca0> whose view is not in the window hierarchy!
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/01 12:20
2018/12/01 13:33 編集
退会済みユーザー
2018/12/01 13:48
2018/12/01 14:07
2018/12/02 05:33