开发者

Call a method on a class whose instance is owned by another

开发者 https://www.devze.com 2023-03-18 19:55 出处:网络
I have two classes, both inherited from NSObject. One is called class1, the other is called class2. They both each have one instance, class1->obj1, and class2->obj2.

I have two classes, both inherited from NSObject. One is called class1, the other is called class2. They both each have one instance, class1->obj1, and class2->obj2.

In class1's init method, I make the instance of开发者_如何学Go class2. From obj2's init method I want to call the instance method -(void)methode from obj1

How do I do this (what are delegates, could I use one)?


- initWithThingy:(Class1 *)anObj
{
    self = [super init];
    if (self) {
        obj1 = [anObj retain]; // or use your set method/property, if you have one
        [obj1 methode];
    }
    return self;
}
0

精彩评论

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