我有一個包含三個對象的字典,我想將該字典添加到堆棧的前一個視圖中的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