Is it possible to programmatically get the identif

2019-04-29 13:06发布

I know that we can instantiate a particular UIViewController basing on its identifier (see below):

var myPageContentViewController = self.storyboard!.instantiateViewControllerWithIdentifier("A") as PageContentViewController

But my question doesn't concern that point, in other words I just would like to know if it would be possible to programmatically (in the source code) retrieve the identifier (in our case the string value "A") that I set in the storyboard for this particular PageContentViewController (which is a subclass of UIViewController in my project)?

Note: an answer using the Swift development language instead of the Objective-C development language would be more convenient for me, even if I know the latter. For your information, I use the 6.0.1 version of Xcode.

Thank you in advance for your answers.

2条回答
你好瞎i
2楼-- · 2019-04-29 13:13

You can get the identifier of the UIViewController by using the restoration identifier with the following code in objective C:

NSString *restorationId = self.restorationIdentifier;

Hope this will help you.

查看更多
3楼-- · 2019-04-29 13:23

In Swift:

 var str: String! = self.restorationIdentifier
查看更多
登录 后发表回答