2016-11-21 6 views
0

タブバーを変更するにはどうすればよいですか?私はこの投稿が重複しているように見えますが、私はそれに似た疑問を見つけることはできません。今の私の現在のスイッチタブバーにデータ送信が含まれています

のselectedIndex = 0

ので、私もそれが= 2

selectedIndexのあるタブ番号3に行くようにしたいしかし、私currentViewからnextViewにデータを送信したい私はプッシュ+のselectedIndexを使用している場合には、タブ3に進みますが、selectedIndexの= 0からビューをプッシュし、データはあなたが、これはデータを送信しようとすることができるのselectedIndex = 2 私の現在のコード

func redeemBtnPressed(_ sender: UIButton) { 

     let selectedRedeemBtnInfo = fixedGridInfo[sender.tag] as! Dictionary<String, AnyObject> 
     sender.showsTouchWhenHighlighted = true 

     let storyboard = UIStoryboard(name: "FlightExploration", bundle: nil) 
     let searchFlightVC = storyboard.instantiateViewController(withIdentifier: "SearchFlightVC") as! SearchFlightViewController 

     var newFlightType = String() 

     if "\(selectedRedeemBtnInfo["FlightType"]!)" == "Return" { 
      newFlightType = "Round" 
     } else { 
      newFlightType = "One" 
     } 

     searchFlightVC.flightType = newFlightType 
     searchFlightVC.fromHome = true 
     searchFlightVC.departure = "\(selectedRedeemBtnInfo["Departure"]!) (\(selectedRedeemBtnInfo["DepartureCityCode"]!)" 
     searchFlightVC.arrival = "\(selectedRedeemBtnInfo["Destination"]!) (\(selectedRedeemBtnInfo["DestinationCityCode"]!)" 
     self.navigationController?.pushViewController(searchFlightVC, animated: true) 
     tabBarController?.selectedIndex = 2 
    } 
+0

あなたは 'searchFlightVC'をプッシュする問題を解決タブ3のナビゲーションの右側にありますか? –

+0

タブ0で何らかのアクションをクリックすると、いくつかのデータが送信されてタブが2に変わるはずですか? –

+0

@NiravDの並べ替えのように、限り、私は選択したタブ3のすべてのそれらのデータを変更することができます。と同じビューにタブ1の滞在 –

答えて

0

に送信しないがあります私を助けてくれそうですRajatの答えから修正UITabBarController

var yourViewController : TempViewController 
    if let arrController = tabBarController?.viewControllers { 
     for vc in arrController { 
      if vc is TempViewController { 
       yourViewController = vc as! TempViewController 
      } 
     } 
    } 

    yourViewController.yourData = dataToPass 
    tabBarController?.selectedIndex = 2 
0

のViewControllerをであることのUIViewControllerにに

func redeemBtnPressed(_ sender: UIButton) { 

     let selectedRedeemBtnInfo = fixedGridInfo[sender.tag] as! Dictionary<String, AnyObject> 
     sender.showsTouchWhenHighlighted = true 

     var newFlightType = String() 

     if "\(selectedRedeemBtnInfo["FlightType"]!)" == "Return" { 
      newFlightType = "Round" 
     } else { 
      newFlightType = "One" 
     } 

     if let arrController = tabBarController?.viewControllers { 
      for vc in arrController { 
       if vc.childViewControllers[0] is SearchFlightViewController { 
        let displayViewController = vc.childViewControllers[0] as! SearchFlightViewController 
        let _ = displayViewController.navigationController?.popToRootViewController(animated: true) 
        //displayViewController.flightType = newFlightType 
        displayViewController.flightTypeFromHome = newFlightType 
        displayViewController.fromHome = true 
        displayViewController.departure = "\(selectedRedeemBtnInfo["Departure"]!) (\(selectedRedeemBtnInfo["DepartureCityCode"]!)" 
        displayViewController.arrival = "\(selectedRedeemBtnInfo["Destination"]!) (\(selectedRedeemBtnInfo["DestinationCityCode"]!)" 
        displayViewController.flightType = "Round" 

        displayViewController.departureDateLbl = "Select One" 
        displayViewController.passenger = "1 Adult" 
        displayViewController.adultCount = 1 
        displayViewController.childCount = Int() 
        displayViewController.infantCount = Int() 
        tabBarController?.selectedIndex = 2 
        tabBarController?.tabBar((tabBarController?.tabBar)!, didSelect: (tabBarController?.tabBar.items?[2])!) 
       } 
      } 
     } 

    } 
関連する問題