问题
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