以编程方式返回选项卡栏控制器中的视图

时间:2016-07-13 16:19:13

标签: ios swift tabbar

我有一个带有5个ViewControllers的TabBarController,在其中一个ViewControllers上,我有一组按钮,可以在TabBarController之外加载不同的视图控制器。这些是通过Modal Segue来加载的,但是我遇到的问题是当我尝试回到它所加载的Tab栏中的View时,但是没有Tab Bar本身,我的代码是:

class GreetingsVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func goBack(sender: AnyObject) {

        let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
        let nextViewController = storyBoard.instantiateViewControllerWithIdentifier("anonScreen") as! AnonVC
        self.presentViewController(nextViewController, animated:true, completion:nil)
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}

如何在按下后退按钮的情况下进行操作,它会从标签栏控制器中显示视图控制器?

1 个答案:

答案 0 :(得分:1)

根据我的理解,从tabbar控制器中,您使用presentViewController呈现了GreetingsVC,并且您想要返回上一个视图(其中一个标签栏视图控制器)

您需要使用presentViewController

,而不是使用dismissViewControllerAnimated
@IBAction func goBack(sender: AnyObject) {

    dismissViewControllerAnimated(true, completion: nil)
}