如何将屏幕从一个TabBarItem传递到另一个TabBarItem?

时间:2017-09-12 11:13:01

标签: ios swift uitabbarcontroller segue

enter image description here

在上图中,

选项卡栏中的

1.标签栏项目 A - > C - > d 而不是

选项卡栏中的

3. tabbar项目 按照顺序 E - > D - >甲

App会记住1.标签栏项目上的D屏幕。我想要" A"屏幕打开。

以下代码;

D ViewController:

   @IBAction func goToMapButton(_ sender: Any) {

        if let navController = self.tabBarController?.viewControllers?[0] as? UINavigationController{
            if let mapController = navController.childViewControllers.first as? MapViewController{
                self.tabBarController?.selectedIndex = 0
                mapController.zoomToGeo(X: Double(PhotoItemArraySelected[0].photoLon!)!, Y: Double(PhotoItemArraySelected[0].photoLat!)!,TesisAdi: PhotoItemArraySelected[0].photoName)

            }
        }

        dismiss(animated: true, completion: nil)
   }

1 个答案:

答案 0 :(得分:2)

如果要显示属于选项卡1的屏幕A,屏幕A看起来是MapViewController:

if let navController = self.tabBarController?.viewControllers?[0] as? UINavigationController{
    if let mapController = navController.childViewControllers.first as? MapViewController{
        self.tabBarController?.selectedIndex = 0
        mapController.zoomToGeo(X: Double(PhotoItemArraySelected[0].photoLon!)!, Y: Double(PhotoItemArraySelected[0].photoLat!)!,TesisAdi: PhotoItemArraySelected[0].photoName)

        //add this line and to check if it works good or not.
        navController.popToViewController(mapController, animated: true)
    }
}