Is it possible to programmatically get the identifier of a basic UIViewController from an UIViewController or Storyboard in Swift/Objective-C?

吃可爱长大的小学妹 提交于 2019-12-10 02:54:16

问题


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.


回答1:


In Swift:

 var str: String! = self.restorationIdentifier



回答2:


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.



来源:https://stackoverflow.com/questions/26229355/is-it-possible-to-programmatically-get-the-identifier-of-a-basic-uiviewcontrolle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!