我有一个包含三个对象的字典,我想将该字典添加到堆栈的前一个视图中的NSMutableArray。该数组在mainviewcontroller中正确合成。但是,当我尝试从另一个视图添加对象到NSMutableArray
[mainVC.fotoObjectArray addObject:[NSMutableDictionary dictionaryWithDictionary:fotoObject]];
没有添加到阵列。
看起来好像我没有正确地分配/初始化它,但它保留在前一个视图控制器的属性中。
用户拍摄照片,或者使用按钮从相册中进行选择。当他返回:
PhotoViewController.m
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSArray *viewControllers = [self.navigationController viewControllers];
MainViewController *mainVC = (MainViewController *)[viewControllers objectAtIndex:viewControllers.count - 2];
[mainVC setFotoGenomen:@"Ja"];
i = @"foto";
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
NSData *imageData = UIImageJPEGRepresentation(image, 0.5);
[fotoObject setObject:[NSData dataWithData:imageData] forKey:@"image"];
[mainVC.fotoObjectArray addObject:[NSMutableDictionary dictionaryWithDictionary:fotoObject]];
//display image
UIImageView *imageView = [[UIImageView alloc] init];
[imageView setFrame:CGRectMake(10.0f, 120.0f, 300.0f, 300.0f)];
imageView.backgroundColor = [UIColor whiteColor];
[[self view] addSubview:imageView];
[imageView setImage:image];
[self dismissModalViewControllerAnimated:YES];
[self.tableView reloadData];
[imageView release];
}
在当视图被加载
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
CLLocationCoordinate2D location = newLocation.coordinate;
fotoObject = [[NSMutableDictionary alloc] init];
[fotoObject setObject:[NSNumber numberWithDouble:location.latitude] forKey:@"latitude"];
[fotoObject setObject:[NSNumber numberWithDouble:location.longitude] forKey:@"longitude"];
}
的GPS得到的PhotoViewController.m登录同一时间 'fotoObject' 字典包含正确键和值。现在只需要将该字典放在MainViewController.m的NSMutableArray中。
检查调试器mainVC实际上是你认为它的对象 - 如果你记录mainVC.fotoObjectArray你会看到什么东西吗?那里有其他物体吗? – jrturton
不,当我登录时,它返回null – MaikelS
mainVC或mainVC.fotoObjectArray? – jrturton