내 viewview 셀에서 다른 viewcontroller의 다른 collectionview 셀로 segue를 만들고 싶습니다. 예를 들어 첫 번째 셀을 두드리면 다른 viewcontroller에서 다른 collectionview의 첫 번째 셀로 이동하려고합니다. 또는 두 번째 셀을 두드리면 두 번째 셀로 가고 싶습니다. 내가 어떻게 이걸 얻을 수 있니?어떻게 collectionview 셀에서 다른 collectionview 셀로 segue를 만들 수 있습니까?
0
A
답변
0
하나의 viewcontroller에서 컬렉션 뷰 셀의 segue를 직접 다른 뷰 컨트롤러의 다른 셀로 이동할 수는 없습니다. 그러나 그것은 다음과 유사한 수행하여 당신은 당신이 원하는 것을 달성 할 수 있어야한다 :
부모의 ViewController
1
)를 NSIndexPath스토리 보드 2) 설정 (또는 년을 유형의 속성 selectedIndexPath 추가 이 뷰 컨트롤러가 UICollectionViewDelegate
3) 컬렉션보기 위해 didSelectItemAtIndexPath 위임 메소드를 구현을 구현하는 코드)
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
selectedIndexPath = indexPath
[self performSegueWithIdentifier:@"identifier" sender:self];
}
4) NSIndexPath에게 2보기 컨트롤러
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// :: Should do other checking - if we have segues to other screens
SecondViewController *secondViewController = (SecondViewController *)segue.destinationViewController;
secondViewController.initialDisplayedCellIndexPath = selectedIndexPath
}
}
SecondViewController 코드
1) 유형의 속성 initialDisplayCellIndexPath 추가로
2) 재정의 viewWillAppear
을 selectedIndexPath 값을 전달(이것은 사용자의 collectionV 셀을 클릭의 결과로 코드 트리거 - iew 속성은
[self.view layoutIfNeeded];
[self.collectionView scrollToItemAtIndexPath:initialDisplayCellIndexPath atScrollPosition:UICollectionViewScrollPositionCenteredVertically
는 기본적으로 어떤 위의 두 번째 뷰 컨트롤러에 하나의 뷰 컨트롤러에서 정상 SEGUE을하고하고있다) collectionView 지정됩니다. prepareForSegue의 일부로 두 번째보기 컨트롤러 (이 경우 선택한 항목의 indexPath 임)에 데이터를 전달할 수 있습니다. 그런 다음 두 번째 viewcontroller가 표시되면 콜렉션 뷰에 우리가 가고 싶은 곳으로 스크롤하도록 지시합니다.
희망 사항 :-)
관련 문제
- 1. UIScrollView를 셀로 사용하는 CollectionView
- 2. CollectionView
- 3. CollectionView
- 4. collectionView didSelectItemAtIndexPath
- 5. CollectionView 다른 셀 선택
- 6. CollectionView 셀에서 UIImageView를 집기 확대/축소
- 7. collectionview 셀에서 uiview에 제스처 인식기를 추가하는 방법
- 8. CollectionView 셀에서 문자열을 표시하는 방법은 무엇입니까?
- 9. collectionView 셀에서 UILabel에 그라디언트 추가 - 빠른
- 10. 다른 요소에 Marionette CollectionView 배치하기
- 11. Backbone.Marionette - 다른 ItemView 클래스가있는 CollectionView
- 12. Collectionview 셀의 배경색이 다른 경우
- 13. Coredata + CollectionView
- 14. Collectionview CustomLayout
- 15. popover에서 돌아온 후 collectionview 셀에서 텍스트 필드를 채우는 방법
- 16. CollectionView 여백이 동일하지 않습니다
- 17. Collectionview 또는 tableview?
- 18. CollectionView 헤더의 레이블 문제
- 19. CollectionView Cell segue
- 20. CollectionView 무엇으로 변경합니까?
- 21. StoryBoard의 CollectionView 헤더에보기 추가
- 22. CollectionView 및 회전 문제
- 23. CollectionView 셀의 좌우 정렬
- 24. 간단한 collectionView 애니메이션
- 25. CollectionView 셀 선택시 이동
- 26. prepareForSegue - CollectionView/TableView
- 27. TapGesture within collectionView
- 28. IE9 문제 CollectionView tagName 테이블에 itemViewClass가 CollectionView 인 tagName tr
- 29. Swift에서 인덱싱 된 CollectionView
- 30. 헤더가있는 collectionview 구성
답장을 보내 주셔서 감사합니다. 네가 말한 모든 것을 다했는데 내가 셀을 가볍게 때리면 부서진다. viewWillAppear 내의 scrollToItemAtIndexPath 부분을 주석 처리 할 때 segue는 작동하지만 모든 셀이 두 번째보기 컨트롤러의 첫 번째 셀로 이동합니다 –
이것은 오류입니다 : 캐치되지 않은 예외 'NSInvalidArgumentException'으로 인한 응용 프로그램 종료 중 이유 : '스크롤 시도 잘못된 인덱스 경로 :