I am having an issue with inputting information from one view controller into another. This function is in the second viewcontroller and is called multiple times in the first controller as it is in a for loop and there are multiple objects I want added to the array transfer_array. The objects are of type Poi and consist of a imageLocationX, imageLocationY, and name. The reason I have the BOOL was my attempt at only initializing the array once. The Poi object is added to the array the first time the function is called and the array is empty after the function is called again.
- (id)display:(double)imageXX andY:(double)imageYY withName:(NSString *)namee ifDone:(BOOL *)donee{
NSLog(@"````````````````````````````````````````````````````````");
NSLog(donee ? @"Yes" : @"No");
if(donee == NO){
transfer_array = [[NSMutableArray alloc] init];
}
NSLog(@"imageX: %f",imageXX);
NSLog(@"imageY: %f", imageYY);
NSLog(@"name: %@", namee);
labelPoi = [[Poi alloc] init];
labelPoi.imageLocationX = imageXX;
labelPoi.imageLocationY = imageYY;
labelPoi.name = namee;
[transfer_array addObject:labelPoi];
NSLog(@"label.x: %f should be: %f", labelPoi.imageLocationX, imageXX);
NSLog(@"label.y: %f should be: %f", labelPoi.imageLocationY, imageYY);
NSLog(@"label.name: %@ should be: %@",labelPoi.name,namee);
NSLog(@"transssssfer: %lu", (unsigned long)transfer_array.count);
return self;
}
Here is the log from the first time the function is called:
````````````````````````````````````````````````````````
2013-07-29 13:25:52.502 App[20856:11303] No
2013-07-29 13:25:52.502 App[20856:11303] imageX: 979.008057
2013-07-29 13:25:52.503 App[20856:11303] imageY: 115.728180
2013-07-29 13:25:52.503 App[20856:11303] name: Urgent Care
2013-07-29 13:25:52.503 App[20856:11303] label.x: 979.008057 should be: 979.008057
2013-07-29 13:25:52.503 App[20856:11303] label.y: 115.728180 should be: 115.728180
2013-07-29 13:25:52.503 App[20856:11303] label.name: Urgent Care should be: Urgent Care
2013-07-29 13:25:52.503 App[20856:11303] transfer_array.count: 1
And the second time:
2013-07-29 13:25:52.506 App[20856:11303] ````````````````````````````````````````````````````````
2013-07-29 13:25:52.506 App[20856:11303] Yes
2013-07-29 13:25:52.506 App[20856:11303] imageX: 224.485718
2013-07-29 13:25:52.506 App[20856:11303] imageY: 116.353401
2013-07-29 13:25:52.506 App[20856:11303] name: Student Health Center
2013-07-29 13:25:52.507 App[20856:11303] label.x: 224.485718 should be: 224.485718
2013-07-29 13:25:52.507 App[20856:11303] label.y: 116.353401 should be: 116.353401
2013-07-29 13:25:52.507 App[20856:11303] label.name: Student Health Center should be: Student Health Center
2013-07-29 13:25:52.507 App[20856:11303] transfer_array.count: 0
I cannot access any of the information in the array because it is empty. Does anyone know how I can modify this so that the function will continually add the objects I want to add instead of remaining empty?
EDIT
This was how the function was called in the first view controller and this method was suggested to me by a friend
PictureViewController *newlabel = [[PictureViewController alloc] display:PointOfInterest.imageLocationX andY:PointOfInterest.imageLocationY withName:PointOfInterest.name ifDone:done];
if(done == NO){
done = YES;
}
transfer_arrayvariable declared?@property (nonatomic,retain)NSArray *transfer_array;in the .h file and@synthesize transfer_array;in the .m file for the second view controllerself.transfer_array, but do it with an autoreleased object:self.transfer_array = [NSMutableArray array];.[transfer_array addObject:labelPoi];??