ios 如何在故事板中为视图控制器提供“标识符”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15478411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 22:46:02  来源:igfitidea点击:

How do I give an "identifier" to a view controller within my storyboard?

iosobjective-cxcodeuiviewcontrollerstoryboard

提问by Doug Smith

The instantiateViewControllerWithIdentifier:method requires that the view controller I pass have an identifier. I went to my storyboard and clicked on my view controller, but I see no option to set the identifier. Where exactly do I find this option?

instantiateViewControllerWithIdentifier:方法要求我传递的视图控制器具有标识符。我转到我的故事板并单击我的视图控制器,但我看不到设置标识符的选项。我在哪里可以找到这个选项?

回答by Groot

As the Image suggests! Hope it helps!

如图所示!希望能帮助到你!

enter image description here

在此处输入图片说明

Then to use it you call:

然后使用它你调用:

[self.storyboard instantiateViewControllerWithIdentifier:@"YourViewControllerID"];

回答by Taiwosam

Updated for XCode 8 and Swift 3.

针对 XCode 8 和 Swift 3 进行了更新。

instantiateViewControllerWithIdentifieris now instantiateViewController(withIdentifier:).

instantiateViewControllerWithIdentifier现在是instantiateViewController(withIdentifier:)

Setting the storyboard ID: enter image description here

设置故事板 ID: 在此处输入图片说明

回答by Felix

In the identity inspectorthere is a field Storyboard ID. You could enter the class name here and then use this identifier in instantiateViewControllerWithIdentifier:.

身份检查器中有一个字段Storyboard ID。您可以在此处输入类名,然后在instantiateViewControllerWithIdentifier:.