前提・実現したいこと
XLPagerTabStripを利用して、3つタブのある画面を生成しています。
遷移元で非同期通信を行い、結果が帰ってきた際にその値をXLPagerTabStripで生成した画面に渡したいのですが、方法がわかりません。
AppDelegateや変数用のクラスを設ければ可能なのでしょうが、通常の遷移で下記のように実装している形で実装は出来ないのでしょうか?
swift
1let viewController = storyboard.instantiateViewController(withIdentifier: "Detail") as! DetailView 2viewController.detailText = sampleText 3navigationController?.pushViewController(viewController, animated: true)
該当のソースコード
swift
1// 遷移する際のコード 2 3func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 4 let viewController = storyboard.instantiateViewController(withIdentifier: "Sample") as! SampleBaseView 5 navigationController?.pushViewController(viewController, animated: true) 6}
swift
1// XLPagerTabStripのベースとなるページ 2 3import UIKit 4import XLPagerTabStrip 5 6class SampleBaseView: ButtonBarPagerTabStripViewController { 7 8 override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] { 9 let firstVC = storyboard?.instantiateViewController(withIdentifier: "Tab1") 10 let secondVC = storyboard?.instantiateViewController(withIdentifier: "Tab2") 11 let thirdVC = storyboard?.instantiateViewController(withIdentifier: "Tab3") 12 let childViewControllers: [UIViewController] = [firstVC!, secondVC!, thirdVC!] 13 return childViewControllers 14 } 15 16}
swift
1// 表示するタブ1 2 3import UIKit 4import XLPagerTabStrip 5 6class Tab1: UIViewController { 7 8 var testText = "ここに渡したい" 9 10 override func viewDidLoad() { 11 super.viewDidLoad() 12 13 print(testText) 14 } 15} 16 17extension Tab1: IndicatorInfoProvider { 18 func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo { 19 return "タブ1" 20 } 21}
補足情報(FW/ツールのバージョンなど)
・Xcode9.4.1
・Swift4.1
###追記
swift
1let viewController = storyboard.instantiateViewController(withIdentifier: "Sample") as! SampleBaseView 2let detail = viewController.childViewControllers[0] as! Tab1 3detail.testText = "sampleString"
上記のようにやってみましたが下記のエラーになりました。
libc++abi.dylib: terminating with uncaught exception of type NSException」
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/19 05:14
2018/06/19 05:17