2013-05-20 2 views
0

콜렉션 뷰가있는 아이폰 포토 갤러리를 상세보기로 복제하려는 마음이 천천히 떨어지고 있습니다. 세부 사항보기에 사진 갤러리와 마찬가지로 페이징 기능을 달기를 원합니다. 않습니다. 지금까지 코드를로드하는 것 같지만 오류가 있습니다. 면제 중단 점이 있고 중단 점 1.1 충돌 지점은 self.imageView.image = img; 줄입니다. 이것은 (lldb) 이외의 로그에있는 오류에 대해서는 언급하지 않습니다.컬렉션보기에서 상세보기 문제로 연결

제가 잘못 읽은 부분을 지적하고 누군가를 고칠 수 있는지 궁금합니다. . 나는 또한 상세 뷰에 걸쳐 각 이미지에 대한 제목을하고 싶지만 어디에서 이것을 추가하는 방법/몰랐다

내가 가진 코드는 다음과 같습니다

#import "MarbleCollectionViewController.h" 
#import "DetailViewController.h" 

@interface MarbleCollectionViewController() { 

    NSArray *marbleImages; 
} 

@end 

@implementation MarbleCollectionViewController 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    marbleImages = [NSArray arrayWithObjects:@"arabescato.jpg", 
        @"bianco-carrara.jpg", 
        @"botticino-classico2.jpg", 
        @"Calacatta_Oro.jpg", 
        @"crema-marfil-3.jpg", 
        @"crema-valencia.jpg", 
        @"emperador-dark.jpg", 
        @"jura-beige.jpg", 
        @"nero-marquina.jpg", 
        @"perlato-olympo.jpg", 
        @"rojo-alicante_marbleGRP1.jpg", nil]; 
} 

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 
    return marbleImages.count; 
} 


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{ 
    static NSString *identifier = @"Cell"; 

    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; 

    UIImageView *marbleImageView = (UIImageView *)[cell viewWithTag:100]; 
    marbleImageView.image = [UIImage imageNamed:[marbleImages objectAtIndex:indexPath.row]]; 

    return cell; 
} 

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [self performSegueWithIdentifier:@"detailView" sender:collectionView]; 
} 

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    if ([segue.identifier isEqualToString:@"detailView"]) { 
     DetailViewController *destViewController = segue.destinationViewController; 
     NSIndexPath *indexPath = [[self.collectionView indexPathsForSelectedItems] objectAtIndex:0]; 
     destViewController.img = [marbleImages objectAtIndex:indexPath.row]; 
     [self.collectionView deselectItemAtIndexPath:indexPath animated:NO]; 
    } 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 

및 상세보기 is :

당신이 제공 할 수있는 도움에 감사드립니다. 나는 정말 감사하고 있습니다. - 뭔가를 호출하지 않는

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.imageView.image = [UIImage imageNamed:img]; 
} 

이것은 이름에 좋은 교훈이 될해야합니다

+0

어떤 오류가 발생했는지 말하지 않았습니다. – meda

+0

면제 중단 점이 있고 중단 점 1.1 충돌 지점은 줄 self.imageView.image = img;입니다. 이것은 (lldb) 이외의 로그 오류에 대해서는 아무 것도 말하지 않습니다 – David

답변

1

당신은 당신의 DetailViewController에, 이미지에없는 이미지의 경로를 전달하는, 그래서 당신의 viewDidLoad가 있어야합니다 이미지 (또는 img)가 아니라면 그것은 혼란에 빠지게됩니다. imageName 또는 imagePath와 같이 좀 더 설명적인 이름을 붙입니다.

+0

지금까지 도움을 주셔서 감사합니다! 여전히 작동하지 않는, 말합니다 - 'NSString *'형식의 매개 변수에 'UIImage * __ strong'을 보내는 호환되지 않는 포인터 유형 – David

+0

마침내 오류 보고서가 표시됨 - *** 캐치되지 않은 예외 'NSRangeException'으로 인해 응용 프로그램 종료, 이유 : *** - [__ NSArrayI objectAtIndex :] : 빈 배열의 범위를 넘어서는 인덱스 0입니다. ' – David

+0

@David, DetailViewController에서 img가 어떻게 선언됩니까? 문자열로 선언해야합니다. 범위 예외 오류는 내가 생각하는 다른 문제입니다. 그 오류는 어떤 행에서 발생합니까? – rdelmar

관련 문제