如何从iPhone中的子视图访问视图的实例变量
我是 iphone 开发的新手。我想从 uiview 子视图访问 uiview 中声明的实例变量。请帮助我。谢谢。
I am new to iphone development.I want to to access the instance variable declared in uiview from its uiview subview.please help me out .Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从技术上讲,您只需在子级实例方法之一中执行
[[self superview] foo]
即可,这将使您可以访问父级上的foo
属性(您不过,可能必须投射超级视图)。但需要考虑的是,在分层数据结构(如 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 thefoo
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 有一个
superview
属性,该属性将指向视图的超级视图(如果有的话)。您可以向它指向的对象发送消息。
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.