开发者

iphone parent-child objects relationship

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 pleas开发者_StackOverflow中文版e explain why!)


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].

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 assigns self to it after instantiating the child object or your child object exposes an init... method that lets you pass it in.


Use the super keyword: [super parentMethod]

See this answer: What exactly is super in Objective-C?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜