这里先说下通用的方法:
手动用代码建好的view controller,即不是在storyboard中建立的:
var vc = ViewController() self.presentViewController(vc, animated: true, completion: nil) return
在storyboard中建立的可以用下面的代码:
let sb = UIStoryboard(name:"Main", bundle: nil) let vc = sb.instantiateViewControllerWithIdentifier("tabBarController") as ViewController self.presentViewController(vc, animated: true, completion: nil)
这里的tabBarController 是你在storyboard中对相应的viewcontroller打开其identifier inspector,然后对其storyboard ID起的名字。
所以我的程序就是,在A的类中,定义下面的button action:
@IBAction func login(sender: UIButton) { let sb = UIStoryboard(name: "Main", bundle: nil) let vc = sb.instantiateViewControllerWithIdentifier("tabBarController") as UITabBarController self.presentViewController(vc, animated: true, completion: nil) }
如果你的storyboard中是viewcontroller,就as成viewcontroller,如果是UITabBarController就as成为UITabBarController,如果是其它的诸如UITableViewController
浙公网安备 33010602011771号