我是 Objective-C 的初学者。我想从 file调用two
file 中的方法。您能否用下面显示的简单示例教我理解。谢谢!you.m
me.m
你.h
#import <Foundation/Foundation.h>
@interface you : NSObject {
}
- (NSString *)one;
- (NSString *)two;
@end
你.m
#import "you.m"
@implementation you
- (NSString *)one {
NSString *a = @"this is a test.";
return a;
}
-(NSString *)two {
NSString *b = [self one];
return b;
}
@end
我.h
#import <Foundation/Foundation.h>
@interface me : NSObject {
}
@end
我
#import "you.h"
#import "me.h"
@implementation me
-(void)awakeFromNib{
//NSString *obj = [[[NSString alloc] init] autorelease];
//NSString *str = [obj two]; // dont work
//NSString *str = [self two]; // dont work
// I'd like to call method *two* from here.
NSLog(@"%@", str);
}
@end