如何以编程方式访问视图控制器故事板 ID
How can I access a view controller's storyboard id programatically
我试过 self.view.accessibilityIdentifier
和 storyboard?.accessibilityAttributedLabel
,它们都不包含故事板 ID 值。那么呢?
编辑:我找到了这个问题的过时答案,swift 4 或最近的 xcode 版本
How to know the current storyboard name?
如果您在身份检查器中将 "Use Storyboard ID" 设置为 "yes",这在 ViewDidLoad 中有效:
if let str = self.restorationIdentifier {
//Do something with the View Controller's Storyboard ID
}
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "endGame") as! EndViewController
present(vc, animated: false, completion: nil)
在 identity inspector 的情节提要中放入你的情节提要 ID,我的是 "endGame" 并且你还需要添加一个新的 cocoa touch class 然后你也需要在 identity inspector 中在其中添加该 ViewControllers 名称。我的是 EndViewController。然后使用上面的代码。
我试过 self.view.accessibilityIdentifier
和 storyboard?.accessibilityAttributedLabel
,它们都不包含故事板 ID 值。那么呢?
编辑:我找到了这个问题的过时答案,swift 4 或最近的 xcode 版本
How to know the current storyboard name?
如果您在身份检查器中将 "Use Storyboard ID" 设置为 "yes",这在 ViewDidLoad 中有效:
if let str = self.restorationIdentifier {
//Do something with the View Controller's Storyboard ID
}
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "endGame") as! EndViewController
present(vc, animated: false, completion: nil)
在 identity inspector 的情节提要中放入你的情节提要 ID,我的是 "endGame" 并且你还需要添加一个新的 cocoa touch class 然后你也需要在 identity inspector 中在其中添加该 ViewControllers 名称。我的是 EndViewController。然后使用上面的代码。