前提
MacOS 12.5.1
Xcode Version 13.4.1
Swift version 5.6.1
MapsSDK for iOS
実現したいこと
UIViewControllerからAddSubViewし表示したUIView(xib)から、他のUIViewControllerに遷移したいです。
①GoogleMapのMarkerをタップ
②①のMarkerからinfoView(Markerの位置に小窓)を表示
③infoView内のButtonを押す
④他のUIViewControllerに遷移
発生している問題・エラーメッセージ
UIView→UIViewControllerの遷移ができない。。
試したこと
UIView Classは、UIViewControllerではないので、UIView Classに直接「present」の処理を書くとエラーが出ました。
また、UIView・遷移用のButtonは、GoogleMap内に動的に配置されていることから、「segue」「ctrl + ドラッグ」による遷移ができません。
ので、
UIView Classには、遷移元のUIViewControllerのインスタンスを書いていて、以下のような構図でUI遷移を試みました。
UI遷移のトリガー:UIView Class内のButton押下
UI遷移の処理:遷移元のUIViewController
UIView.swift
1class TestView: UIView{ 2 let testVCInatance = TestUIViewController.testUIViewController 3 4 @IBAction func OnTapButton(_ sender: Any) { 5 testVCInatance.presenter() 6 } 7}
UIViewController.swift
1class TestUIViewController: UIViewController { 2 static let testUIViewController = TestUIViewController() 3 4 func presenter(){ 5 let storyboard = UIStoryboard(name: "Main", bundle: nil) 6 let nextVC = storyboard.instantiateViewController(withIdentifier: "nextVC") as! NextViewController 7 self.present(nextVC, animated: true, completion: nil) 8 print("UI遷移しました!") 9 } 10}
どうすれば、UIView→UIViewControllerをpresentでUI遷移できるのでしょうか?
補足情報
ログを見る限り、presenter()が発火してはいるようです。
TestUIViewControllerとNextViewControllerは、main.storyboad内にありますが、階層にないと言われています。
UIViewは、test.xibに紐付いています。
Attempt to present <testproject.NextViewController: 0x103853e80> on <testproject.TestUIViewController: 0x1050a9a00> (from <testproject.TestUIViewController: 0x1050a9a00>) whose view is not in the window hierarchy. UI遷移しました!
最後に
かなりハマっています。UIView→UIViewControllerを行なっている記事があまり見受けられません。
「そもそも、できない」という気すらしてきました。
できないならできないという情報だけでも、いただけると非常にありがたいです。
ご協力の程、よろしくお願い致します。

回答1件
あなたの回答
tips
プレビュー