简体   繁体   中英

How to Access the UIView of the Container

If I'm currently inside of the ViewController that is inside of a container, how can I access the restoration id of the view. So if I'm currently in the ViewController of the view that is inside of the container. How can I access the restoration id that is in the picture that says "topView" I've tried all these options (most of the options I didn't expect to work, but I've been trying everything):

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)

These all print nil

显示我正在使用还原ID的位置

You need to find which one is the container 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)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM