iphone父子对象关系
我有一个“NewsViewController”,它有一个名为“postViewController”的 PostViewController 类型的属性。我想从 PostViewController 内部调用 NewsViewController 类的方法。做到这一点最简单的方法是什么?
在谷歌搜索这个问题后,似乎我应该使用委托或发送通知,但我希望有一种更简单的方法可以做到这一点,例如 [self.parentparentMethod]
...
请告诉我有一个更简单的方法可以做到这一点! :) (如果没有请解释原因!)
I have a "NewsViewController" which has a property named "postViewController" of type PostViewController. From inside the PostViewController I would like to call a method of the NewsViewController class. What is the easiest way to do this ?
After googling that question, it seems like I should use a delegate or send a notification but I was hoping there would be a simpler way to do this like [self.parent parentMethod]
...
Please tell me there IS a simpler way to do this! :)
(and if there isn't please explain why!)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在最基本的层面上,是代表。在处理
parentMethod
消息的类型的子对象上创建一个属性。在实例化子对象后,您的父对象将self
分配给它,或者您的子对象公开一个init...
方法,让您将其传入。That is a delegate, at its most basic level. Create a property on the child object of a type that handles
parentMethod
messages. Your parent assignsself
to it after instantiating the child object or your child object exposes aninit...
method that lets you pass it in.使用 super 关键字:
[superparentMethod]
请参阅此答案:Objective-C 中的 super 到底是什么?
Use the super keyword:
[super parentMethod]
See this answer: What exactly is super in Objective-C?