如果我当前位于容器内部的ViewController中,如何访问视图的还原ID。因此,如果我当前在容器内部视图的ViewController中。如何访问显示为“ topView”的图片中的还原ID,我已经尝试了所有这些选项(大多数我没想到的选项,但是我一直在尝试所有方法):
print(self.view.window?.rootViewController?.restorationIdentifier)
print(self.view.window?.restorationIdentifier)
print(self.view.window?.superview!.restorationIdentifier)
print(self.view.restorationIdentifier)
print(self.parent?.view.restorationIdentifier)
这些全部打印为零
答案 0 :(得分:-1)
您需要找到哪个是UIView容器。
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
print(self.parent?.view.subviews)
// There are two subviews in this case. The last one is the container view. Your case may be different.
print ((self.parent?.view.subviews[0]) )
print (((self.parent?.view.subviews[1]) as! UIView).restorationIdentifier)
}