下記URLを参考にUICollectionViewControllerから画面遷移時に値を渡そうとしたのですがnilとなってしまいます。
参考URL:https://i-app-tec.com/ios/collectionview-cellselect.html
以下の「受け取れる」の部分だと値を取得できるのですが、
この部分で受け取った値を使用すると「whose view is not in the window hierarchy!」というエラーが表示され
他サイト(swift初心者:画面推移時の「whose view is not in the window hierarchy!」の対処方法)を参考に
viewDidAppear内に処理を書くことにしました。
しかしこちらのviewDidAppearでは値が取得できず参っております。。
受け取り側のソース↓
swift
1import UIKit 2 3class SubViewController: UIViewController { 4 5 var selectedInt: Int! 6 7 override func viewDidLoad() { 8 super.viewDidLoad() 9 print(selectedInt,"受け取れる") 10 // Do any additional setup after loading the view. 11 } 12 13 override func viewDidAppear(_ animated: Bool) { 14 super.viewDidAppear(animated) 15 print(selectedInt,"受け取れない") 16 } 17 18 override func didReceiveMemoryWarning() { 19 super.didReceiveMemoryWarning() 20 } 21 22 /* 23 // MARK: - Navigation 24 25 // In a storyboard-based application, you will often want to do a little preparation before navigation 26 override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 27 // Get the new view controller using segue.destination. 28 // Pass the selected object to the new view controller. 29 } 30 */ 31 32} 33
エラー↓
nil 受け取れる nil 受け取れない Optional(2) 受け取れる 2019-05-26 02:17:19.914809+0900 test7[76598:38573491] Warning: Attempt to present <test7.SubViewController: 0x7ffddac0f8c0> on <test7.TestCollectionViewController: 0x7ffddac08400> whose view is not in the window hierarchy!
「whose view is not in the window hierarchy!」がまだ出ていますが、viewDidLoad内の「print(selectedInt,"受け取れる")」をコメントアウトしても
同じエラーが発生しています…
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。