2014-04-09 2 views
0

콜렉션 뷰에서 상세 뷰 컨트롤러로 데이터를 전달하는 방법을 알아내는 데 도움이 필요합니다. 나는 단순히 이미지를 지나가는 것으로 시작하고있다. 내 코드는 다음과 같습니다 :콜렉션 뷰에서 상세 뷰로 데이터 전달

의 ViewController :

-(MyCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 

    MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CELL" forIndexPath:indexPath]; 

    PFObject *imageObject = [imageFilesArray objectAtIndex:indexPath.row]; 
    __block UIImage *MyPicture = [[UIImage alloc]init]; 
    PFFile *imageFile = [imageObject objectForKey:@"test"]; 


    [imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) { 
     if (!error) { 
      MyPicture = [UIImage imageWithData:data]; 
      cell.CollectionImg.image = [UIImage imageWithData:data]; 
      cell.cellLabel.text = [object objectForKey:@"phone"]; 

     } 
    }]; 

    return cell; 
} 

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{ 
     TopDetailViewController *detailVC = [[TopDetailViewController alloc] initWithNibName:@"TopDetailViewController" bundle:[NSBundle mainBundle]]; 
     detailVC.img= [imageFilesArray objectAtIndex: indexPath.row]; 
     [self.navigationController pushViewController:detailVC animated:YES]; 
    } 

그리고 자세히보기 :

.H

@property (nonatomic, strong) IBOutlet UIImageView *imageView; 
@property (nonatomic, strong) IBOutlet NSString *img; 

하는 .m

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.imageView.image = [UIImage imageNamed:self.img]; 
    // Do any additional setup after loading the view from its nib. 
} 

누군가가 나를 도울 수 있다면 나가 크게 감사 할 것 인 밖으로 이자형.

답변

0

[UIImage imageNamed :] 만 사용하여 앱 번들에있는 이미지를 검색 할 수 있습니다. PDF 파일을 기반으로 런타임에 이러한 이미지를 만드는 것처럼 보이므로 문자열을 상세보기로 전달하고 [UIImage imageNamed :]로로드하면 작동하지 않습니다. 자세히보기에서 이미지 자체를 생성 할 수 있도록 이미지 또는 PFFile 객체에 대한 참조를 전달해야합니다.

+0

그럼 어떻게 써야할까요? 새로운 Detail View Controller에서 개체를 호출 할 수 없습니다. 내가 Xcode에 대해 상당히 새로운 도움을 주셔서 감사합니다. – user3255746

+0

DetailViewController에 "NSString * img"ivar가 있습니까? "UIImage * actualImage"인 다른 이미지를 만들고 같은 방법으로 전달하십시오. –

관련 문제