如何以编程方式访问视图控制器的情节提要ID

时间:2019-01-28 00:22:44

标签: swift xcode storyboard

我尝试过self.view.accessibilityIdentifierstoryboard?.accessibilityAttributedLabel,但它们都不包含情节提要ID值。那是什么呢?

编辑:我已经找到了这个问题的过时答案,对于swift 4或最新的xcode版本没有任何帮助

How to know the current storyboard name?

2 个答案:

答案 0 :(得分:2)

如果在身份检查器中将“使用情节提要ID”设置为“是”,则此方法在ViewDidLoad中有效:

if let str = self.restorationIdentifier {
//Do something with the View Controller's Storyboard ID
}

答案 1 :(得分:0)

let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "endGame") as! EndViewController

        present(vc, animated: false, completion: nil)

在身份检查器的故事板上,将您的故事板ID放入,我的是“ endGame”,并且您还需要添加一个新的可可触摸类,然后在身份检查器中,您还需要在其中添加该ViewControllers名称。我的是EndViewController。然后使用上面的代码。