I have a @property (nonatomic,retain) NSMutableArray *transfer_array; in .h file and in my .m I have
@synthesize transfer_array = _transfer_array;
- (id)init
{
self = [super init];
if(self) {
self.transfer_array = [[NSMutableArray alloc] init];
}
return self;
}
and I add objects to the array in this function
- (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];
The objects add successfully bu whenever I try to access the array elements in another instance such as:
- (void)viewDidLoad{
[super viewDidLoad];
NSLog(@"transfer_array count: %lu",(unsigned long)self.transfer_array.count);
Then the array is empty.
Any help would be appreciated!
- (id)display:(double)imageXX andY:(double)imageYY withName:(NSString *)namee{function? Could you insertNSLog(@"transfer_array count: %lu",(unsigned long)self.transfer_array.count);in your display function, after you added the object to the array and show us the output?NSLog(@"transfer_array count: %lu",(unsigned long)self.transfer_array.count);in the display function and the result is2013-07-30 12:44:57.002 App[24164:11303] transfer_array count: 2