【发布时间】:2011-09-06 16:07:16
【问题描述】:
有人可以帮我引用其他类的数组吗?
这里是 ClassA.h
@interface ClassA : UIViewController <MKMapViewDelegate> {
NSMutableArray *theArray;
}
@property (nonatomic, retain) NSMutableArray *theArray;
-(NSMutableArray *) pleaseReturnTheArray;
@end
ClassA.m
#import "ClassA.h"
@implementation ClassA
@synthesize theArray;
...
-(NSMutableArray *) pleaseReturnTheArray {
return theArray;
}
这里是 ClassB.m(我想引用 ClassA 数组,我有 #import "MapView.h" 到这个类中,这是一个被推送到屏幕上的不同视图)
- (void)viewDidLoad {
[super viewDidLoad];
//first test
ClassA *firstTest = [[ClassA alloc] init];
NSMutableArray *firstTestArray = [firstTest.theArray mutableCopy];
NSLog(@"first test - %@", firstTestArray);
//second test
NSMutableArray *secondTestArray = [firstTest pleaseReturnTheArray];
NSLog(@"second Test - %@", secondTestArray);
...
我得到的 NSLog 中的结果是 ...
first test - (null)
second Test - (null)
我确信我以前使用过其中一种方法并且效果很好。这与 ClassB 是标签栏控制器推送的不同视图这一事实有关吗?
任何帮助将不胜感激。
克里斯
【问题讨论】:
标签: objective-c arrays class