0

我有一个@property (nonatomic,retain) NSMutableArray *transfer_array;.h 文件,我有一个 .m 文件

@synthesize transfer_array = _transfer_array;

- (id)init
{
    self = [super init];
    if(self) {
        self.transfer_array = [[NSMutableArray alloc] init];
    }
    return self;
}

我在这个函数中将对象添加到数组中

- (id)display:(double)imageXX andY:(double)imageYY withName:(NSString *)namee{

    //if((self == [super init])){
    NSLog(@"````````````````````````````````````````````````````````");

    NSLog(@"imageX: %f",imageXX);
    NSLog(@"imageY: %f", imageYY);
    NSLog(@"name: %@", namee);

    labelPoi = [[Poi alloc] init];
    labelPoi.imageLocationX = imageXX;
    labelPoi.imageLocationY = imageYY;
    labelPoi.name = namee;
    [self.transfer_array addObject:labelPoi];

每当我尝试访问另一个实例中的数组元素时,对象就会成功添加,例如:

- (void)viewDidLoad{
    [super viewDidLoad];

    NSLog(@"transfer_array count: %lu",(unsigned long)self.transfer_array.count);

然后数组为空。

任何帮助,将不胜感激!

4

1 回答 1

3

实例是独立的对象。改变一个人的内部状态不会影响他人的内部状态。

于 2013-07-30T17:52:55.230 回答