我想在不同的 View Controller 之间切换,这是我的代码,
let sb = UIStoryboard(name:"Main", bundle: nil)
let vc = sb.instantiateViewControllerWithIdentifier("tabBarController") as ViewController
self.presentViewController(vc, animated: true, completion: nil)
'tabBarController' 是我在标识符检查器中写的 Storyboard ID。但我在这一行遇到了一些错误。
let vc = sb.instantiateViewControllerWithIdentifier("tabBarController") as ViewController
这是截图,
有什么问题?
还有一个问题,这是sb初始化后的截图,storyboardFileName是“Main.storyboardc”,不应该是“Main.storyboard”吗?
非常感谢!!!!
最佳答案
错误表明 instantiateViewControllerWithIdentifier 返回的 View Controller 无法转换为 ViewController。
这可能是因为您没有将 Storyboard 中 View Controller 的 Custom Class 属性设置为 ViewController。
转到 Storyboard,选择 View Controller ,然后打开身份检查器并查找自定义类属性。将其设置为 ViewController 并按 Tab 键退出该字段以确保它可以使用。然后再次运行。
关于ios - 使用 swift 在不同的 View Controller 之间切换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28445804/