How do I give an “identifier” to a view controller

2019-01-09 11:21发布

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?

3条回答
Viruses.
2楼-- · 2019-01-09 12:05

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

查看更多
Ridiculous、
3楼-- · 2019-01-09 12:08

As the Image suggests! Hope it helps!

enter image description here

Then to use it you call:

[self.storyboard instantiateViewControllerWithIdentifier:@"YourViewControllerID"];
查看更多
Root(大扎)
4楼-- · 2019-01-09 12:13

Updated for XCode 8 and Swift 3.

instantiateViewControllerWithIdentifier is now instantiateViewController(withIdentifier:).

Setting the storyboard ID: enter image description here

查看更多
登录 后发表回答