1. 在storyboard里给跳转的viewController加上StoryboardID:
2.代码如下修改
ViewController2 为UIViewController 的id 如上图设置
let controller = self.storyboard?.instantiateViewController(withIdentifier: String(describing: type(of: ViewController2())))
as! ViewController2
self.navigationController?.pushViewController(controller, animated: true)