2011-10-12 6 views
0

세 개의 객체가 포함 된 사전이 있으며이 사전을 스택의 이전 뷰에서 NSMutableArray에 추가하려고합니다. 이 배열은 mainviewcontroller에서 올바르게 합성됩니다. 그러나 시도 할 때다른 뷰에서 NSMutableArray에 객체 추가

[mainVC.fotoObjectArray addObject:[NSMutableDictionary dictionaryWithDictionary:fotoObject]]; 아무 것도 배열에 추가되지 않습니다.

alloc/init 제대로하지 못했지만 이전 뷰 컨트롤러의 속성에서 유지됩니다.

사용자가 사진을 찍거나 단추로 앨범에서 선택합니다. 그가 돌아 오면 : 뷰가

-(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에 기록됩니다 동시에

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]; 

} 

은 'fotoObject'딕셔너리는 권리를 포함 키 및 값. 이제 그 사전을 MainViewController.m의 NSMutableArray에 넣으면됩니다.

+0

디버거에서 mainVC가 실제로 생각하는 객체인지 확인하십시오. mainVC.fotoObjectArray를 로깅하면 아무 것도 보이지 않습니까? 거기에 다른 물건이 있습니까? – jrturton

+0

아니요, 기록 할 때 null을 반환합니다. – MaikelS

+0

mainVC 또는 mainVC.fotoObjectArray? – jrturton

답변

1

mainVC에서 어레이를 초기화하지 않는 것처럼 들립니다. 방금 합성 된 접근자를 얻은 경우 명시 적으로 배열을 설정하지 않으면 nil을 반환합니다. 이것은 당신이 실제로 물건을 추가하는 배열이 있는지 확인합니다

if (!self.fotoObjectArray) 
    self.fotoObjectArray = [NSMutableArray array]; 

: 당신이 뭔가를 할 수 mainVC의 viewDidLoad 방법

.

+0

감사! 그거였다! 나는 그것이 이런 것이었다는 것을 알았다. – MaikelS

관련 문제