我在将信息从一个视图控制器输入到另一个视图控制器时遇到问题。此函数位于第二个视图控制器中,并在第一个控制器中被多次调用,因为它位于 for 循环中,并且我想将多个对象添加到数组 transfer_array 中。对象是 Poi 类型,由 imageLocationX、imageLocationY 和名称组成。我有 BOOL 的原因是我尝试只初始化数组一次。第一次调用函数时将 Poi 对象添加到数组中,再次调用函数后数组为空。
- (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;
}
这是第一次调用该函数时的日志:
````````````````````````````````````````````````````````
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
第二次:
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
我无法访问数组中的任何信息,因为它是空的。有谁知道我如何修改它,以便该函数不断添加我想要添加的对象而不是保持为空?
编辑
这就是在第一个视图控制器中调用该函数的方式,这个方法是一个朋友向我推荐的
PictureViewController *newlabel = [[PictureViewController alloc] display:PointOfInterest.imageLocationX andY:PointOfInterest.imageLocationY withName:PointOfInterest.name ifDone:done];
if(done == NO){
done = YES;
}