How to access first class method from second class in objective c

江枫思渺然 提交于 2019-12-13 09:55:01

问题


I have written two classes which contains same method (print). I want to access first class print method using second class object. How i can achieve this?

Code:

@interface classA : NSObject
-(void) print;
@end

@implementation classA

-(void) print
{
    NSLog(@"hello");
}

@end

@interface classB : classA

-(void) print;
@end

@implementation classB

-(void) print{
    NSLog(@"hey");
}
@end

Now i created second class object like

classB *B = [classB alloc]init];

回答1:


use delegates to access other classes @protocol




回答2:


you can do like this way also

@implementation view1
(void)someMethod
{
   ......code of method...
}

@implementation view2
(void)fistMethod
{
    view1 *abc = [[view1 alloc]init];
    [abc someMethod];
    [abc release];
}

also check this Objective-C call function on another class?



来源:https://stackoverflow.com/questions/13245100/how-to-access-first-class-method-from-second-class-in-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!