简体   繁体   中英

How to access the instance variable of the view from its subview in iphone

我是iphone开发的新手,我想从uiview子视图访问uiview中声明的实例变量。请帮帮我。谢谢。

Technically, you can just do [[self superview] foo] from within one of the child's instance methods and that will give you access to the foo property on the parent (you may have to cast the superview, though). But something to consider is that in hierarchical data structures (like the UIView hierarchy), it's generally good practice for children to not "know" too many of the details of their parents, where possible.

UIView has a superview property that will point to the view's superview if it has one. You can send messages to the object it points to.

view.superview.iVar

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