[英]How to pass data from ViewController to UITabBarController in iOS Swift?
[英]How to passes data from ViewController to UITabBarController -> UINavigationController -> ViewController
我嘗試將數據從ViewController發送到UITabBarController-> UINavigationController-> ViewController,然后嘗試多種方法,但無法傳遞數據。 單擊按鈕后,我有異步任務,然后需要向UITabBarController-ViewController加載一些數據。 我已經幾乎嘗試了所有示例,但是找不到有效的代碼。
func AftergettingAsynchronousData(forUserID userID: String?) {
guard let tabBarController = tabBarController else { return }
let navController = tabBarController.viewControllers?[0] as! UINavigationController
let exploreViewController = navController.topViewController as! ExploreViewController
exploreViewController.userID = userID
}
接收數據
class ExploreViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
public var userID: String?
override func viewDidLoad() {
super.viewDidLoad()
print("userID \(String(describing: userID))");
}
}
嘗試將navController.topViewController更改為navController.rootViewController
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.