2017-09-06 4 views
0

このコードは、サーバーにデータを送信するための保存ボタンです。それが正常に送信された後。ビューコントローラをタブバーコントローラに戻してインデックス2に切り替える方法を教えてください。 .selectedIndexが機能していません。データをサーバーに正常に送信した後、タブバーのインデックスを切り替えるにはどうすればいいですか?

if (result == "success") {          
    self.view.endEditing(true) 
    let alert = UIAlertController(title: "Updated", message: "Update Successfully", preferredStyle: UIAlertControllerStyle.alert) 
    let okButton = UIAlertAction(title: "OK", style: UIAlertActionStyle.cancel, handler: nil) 
    alert.addAction(okButton) 
    self.present(alert, animated: true, completion: nil) 

    let appDelegate = UIApplication.shared.delegate! as! AppDelegate 

    let initialViewController =self.storyboard!.instantiateViewController(withIdentifier: "tabBarVC") 
    appDelegate.window?.rootViewController = initialViewController 
    appDelegate.window?.makeKeyAndVisible() 
    self.tabBarController?.selectedIndex = 2 // this code is not working 
} 
+0

initialViewControllerの種類は何ですか? –

+0

タブバーコントローラー –

答えて

1

はこれを試してみてください -

let initialViewController = self.storyboard!.instantiateViewController(withIdentifier: "tabBarVC") as! UITabBarController 
    appDelegate.window?.rootViewController = initialViewController 
    appDelegate.window?.makeKeyAndVisible() 
    initialViewController.selectedIndex = 2 
+0

UIViewControllerタイプの値にはメンバーがありませんselectedIndex ...そのビューコントローラーと思いますか? –

+0

答えを編集しました、今すぐ確認してください –

関連する問題