0

특정 UICollectionViewCell을 참조하여 각기 다른 VC에 연결되도록하려면 어떻게해야합니까?UICollectionViewCell NSindexpath 참조 위치

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 
    Cell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MY_CELL" forIndexPath:indexPath]; 
    cell.imageView.image = [UIImage imageNamed:self.myCellImages[0]]; 
    UIImage *cellImage = [[UIImage alloc] init]; 
    cellImage = [UIImage imageNamed:[self.myCellImages objectAtIndex:indexPath.row]]; 
    cell.imageView.image = cellImage; 
    return cell; 
} 

그래서 이것이 내가 내 배열에로드 얼마나 많은 이미지에 따라 서로 다른 세포의 무리를 표시합니다 여기

은 셀의 코드입니다.

내 배열 인 의견 : 다른 VC에 segues 있도록

self.myCellImages = @[@"1.jpg", @"2.jpg",.... @"20.jpg"]; 

이 어떻게 개별 셀을 참조합니까?

if (NSIndexPath *indexPath = [NSIndexPath indexPathForItem:0 inSection:0];) 
{ 
//segue here 
} 

내가 할 수없는 그림 : 예를 들어, 셀 with17.jpg이 17VC

에 segues에 이미지 1VC로 segues을 1.JPG 및 클릭이있는 셀을 클릭하면 그것을 같은가요

감사 디모데에게 올바른 구문에서, 나는 당신이 당신의 공동 사이에 segues을 설정해야

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:indexPath 
{ 
    NSString *storyboardId = @"main_to_VC1"; 
    [self performSegueWithIdentifier:storyboardId sender:indexPath]; 
} 

답변

1

추가 (셀이 아닌) 뷰 컨트롤러와 대상 컨트롤러를 사용하여 각 스토리 보드 고유의 스토리 보드 ID를 제공합니다.

- (void)collectionView:collectionView didSelectItemAtIndexPath:indexPath 
{ 
    NSString *storyboardId = ...; // determine storyboard ID based on indexPath 
    [self performSegueWithIdentifier:storyboardId sender:indexPath]; 
} 
+0

안녕 티모시, 당신의 도움을 주셔서 감사합니다 :

그런 다음 collectionView:didSelectItemAtIndexPath: 위임 방법, 당신은 indexPath을 기반으로 SEGUE하고 싶은 프로그래밍 SEGUE을 시작하는 컨트롤러를 결정합니다. 나는 두 개의 segues를 만들고 하나의 main_to_VC1과 또 다른 main_to_VC2를 콜렉션 VC에서 셀이 아니라 "push"로 설정했다. 그런 다음 편집 내 업에 명시된대로 collectionView didSelectItemAtIndexPath를 추가했습니다. 그러나 그것은 main_to_VC1/2가 개별적인 내용을 가지고있을 때보기를 빈 화면으로 전환합니다. 세포를 가지고 뭔가를해야합니까? – user3325170

+0

아! 나는 그것을 고쳤다. 해야 할 일 : (void) collectionView : (UICollectionView *) collectionView 그러나 새 VC에서 뒤로 단추를 누르면 주 컬렉션보기로 돌아갈 때 두 번 눌러야합니다. . 왜 이런 짓을 한거야? – user3325170

+0

흠 ... 내 코드에 잠깐 혼란 스러웠습니다. 그래서, 그것은 작동하지만 각 개별 셀이 서로 다른 VC에 연결되도록 만드는 방법에 관해서는 여전히 혼란 스럽습니다. 이 셀은 재사용이 가능하기 때문에 셀이 실행될 때 20 개의 셀 (배열에 20 개의 항목이있는 경우)이 생성됩니다. 어떻게하면 각자가 자신 만의 VC를 갖고 갈 수 있을까요? – user3325170