ios - 返回 Storyboard当前 View Controller 标识符

标签 ios swift cocoa-touch uiview uiviewcontroller

如何找到实例化的当前 View Controller 的标识符?

例子:

self.storyboard?.instantiateViewControllerWithIdentifier("ThisViewController") as! UIPageViewController

然后使用类似self.storyboard?.currentViewControllerIdentifier 的东西来返回ThisViewController?

最佳答案

来自 UIStoryboard 的文档:

This identifier is not a property of the view controller object itself and is used only by the storyboard file to locate the view controller.

所以简短的回答是你不能。更长的答案是您可以子类化 UIViewController 并为标识符添加一个属性,并在每次从 Storyboard加载时分配该属性。

关于ios - 返回 Storyboard当前 View Controller 标识符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31059082/

相关文章:

ios - 通过函数初始化实例变量

ios - 如何根据 IndexPath.row 设置自定义 UITableViewRowAction?

ios - 使用相同的 UploadKey 从 Posts 同步保存数据

ios - 如何根据 UIAlertController 中的 UITextField 禁用 UIAlertAction?

ios - 具有泛型类型和 UITableview 的 Swift 3 ViewController

iphone - UINavigationController 栈

ios - tableView 显示重复值

ios - 使用 VPN 连接在 iOS 模拟器中运行应用程序

iOS以编程方式撤销位置服务权限

iphone - 使用 UISearchBar 关闭键盘,而不放弃第一响应者