是否有可能以编程方式从Swift / Objective-C中的UIViewController或Storyboard获取基本UIViewController的标识符? [英] Is it possible to programmatically get the identifier of a basic UIViewController from an UIViewController or Storyboard in Swift/Objective-C?
问题描述
我知道我们可以根据其标识符实例化一个特定的UIViewController(见下文):
I know that we can instantiate a particular UIViewController basing on its identifier (see below):
var myPageContentViewController = self.storyboard!.instantiateViewControllerWithIdentifier("A") as PageContentViewController
但我的问题与此无关,换句话说,我只想知道是否有可能以编程方式(在源代码中)检索我在故事板中为这个特定的PageContentViewController设置的标识符(在我们的例子中是字符串值A)(这是一个我项目中UIViewController的子类)?
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)?
注意:使用Swift开发语言而不是Objective-C开发语言的答案对我来说会更方便,即使我知道后者。为了您的信息,我使用Xcode的6.0.1版本。
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.
提前感谢您的答案。
推荐答案
在Swift中:
var str: String! = self.restorationIdentifier
这篇关于是否有可能以编程方式从Swift / Objective-C中的UIViewController或Storyboard获取基本UIViewController的标识符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!