2014-12-17 3 views
0

나는 그림 모음을 보여주는 MainStoryboard.storyboard에서 Collection View를 사용하고 있습니다. 나는 항목, 즉 다음과 같은 방법을 선택한 경우 테이블보기로 수집보기에서 가고 싶은 :collectionView에있는 tableView IOS

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath 

은 어떻게 선택 후 collectionView의 방법에있는 tableView를로드 할 수 있습니다 ?

내 방식 :

UIViewController *vc = [[UIStoryboard storyboardWithName:@"SubCategories" bundle:nil] instantiateViewControllerWithIdentifier:@"SubCategories"]; 
[self.view addSubview:vc.view ]; 
+0

현재 장면에 뷰를 추가하지 않고 새 장면을 분할해야합니다. – Paulw11

+0

콜뷰 뷰의 방법에서이를 수행하려면 자세히 설명해주십시오. @ Paulw11 – developer

+0

'performSegueWithIdentifier' 사용법 검색 – Paulw11

답변

0

당신은 그 안에있는 TableView를 가지고 스토리 보드에서 새의 ViewController를해야한다. 그런 다음 첫 번째 ViewController (VC 자체에서, CollectionView가 아닌)에서 새 ViewController로 segue를 추가합니다. segue에 segue 식별자를 설정했는지 확인하십시오.

는 그런 다음 didSelectItemAtIndexPath 방법에

[self performSegueWithIdentifier:@"YourIdentifier" sender:self]; 

당신은 다음 두 번째 VC로 선택한 것에 대해 데이터를 전달하는 첫 번째 VC의 prepareForSegue 방법을 구현할 수 있습니다 호출합니다.

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { 
    // Make sure your are about to perform the same segue 
    if ([[segue identifier] isEqualToString:@"YourIdentifier"]) { 
     // Get reference to the destination view controller 
     SecondViewController *vc = [segue destinationViewController]; 
     // Pass any objects to the view controller here, like... 
     [vc setMyObjectHere:object]; 
    } 
} 

참고로, prepareForSegue를 호출하지 마십시오. iOS는 segue가 발생하려고 할 때 호출합니다.

관련 문제