开发者

Objective-C calling method from super object.

开发者 https://www.devze.com 2023-03-24 14:13 出处:网络
I have an object called 开发者_JAVA百科\"Object B\", that is spawned by \"Object A\". Is it possible for Object B to call a method in Object A ?Object B must have a property that Object A can set.

I have an object called 开发者_JAVA百科"Object B", that is spawned by "Object A". Is it possible for Object B to call a method in Object A ?


Object B must have a property that Object A can set.

Like this:

@interface B {
  A *a;
}
@property (nonatomic, retain) A *a; // synthesize this
@end

In A:

B *b = [[B alloc] init];
b.a = self;

Then, b can just send messages to a.


Not unless you when spawning "Object B" also pass it a reference to "Object A". For example:

ObjectB* b = [[ObjectB alloc] initWithObjectA:self];
0

精彩评论

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

关注公众号