如何在成功向服务器提交数据后切换标签栏索引?

时间:2017-09-06 10:22:18

标签: swift uitabbarcontroller

此代码是用于将数据发送到服务器的保存按钮。发送成功后。如何让视图控制器返回标签栏控制器并将其切换到索引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
}

1 个答案:

答案 0 :(得分:1)

试试这个 -

...
MaxMaxBackupSize = Convert.ToInt16(f / 1000000000)
TotalSize = (TotalSize < MaxMaxBackupSize) ? TotalSize : MaxMaxBackupSize;
...