0

我有一個標識符MY_CELL和兩個獨立的UICollectionViewCells MY_CELL_2多UICollectionViewCells到Segue公司分離的UIViewController

然後我寫了這個:

#import "MyCollectionView" 
#import "Cell.h" 
#import "VC1.h" 
#import "VC2.h" 

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

      Cell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MY_CELL" forIndexPath:indexPath]; 



     Cell *cell2 = [collectionView dequeueReusableCellWithReuseIdentifier:@"MY_CELL_2" forIndexPath:indexPath]; 



    } 

然後我有兩個UIVCs,UIVC1和UIVC2我想MY_CELL到Segue公司到UIVC1和MY_CELL_2到原因請看UIVC2所以我寫了:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 

    if ([[segue identifier] isEqualToString:@"cell_to_vc1"]) 
    { 

    UICollectionViewCell *cell = (UICollectionViewCell *)sender; 
    NSIndexPath *indexPath = [self.collectionView indexPathForCell:cell]; 

    UIVC1 *vc1 = (VC1 *)segue.destinationViewController; 


    } 

    if ([[segue identifier] isEqualToString:@"cell2_to_vc2"]) 
    { 

     UICollectionViewCell *cell2 = (UICollectionViewCell *)sender; 
    NSIndexPath *indexPath = [self.collectionView indexPathForCell:cell]; 

    UIVC2 *vc2 = (VC2 *)segue.destinationViewController; 

    } 


} 

但是,我甚至不能看到所顯示的第二個單元格。只有MY_CELL可見。

任何人都知道我做錯了,爲什麼我看不到第二個單元?

+0

告訴我什麼是要求? –

+0

@SamkitJain要求是我可以有多個UICollectionViewCells和每個單元格並插入到不同的UIViewController中。所以,單元格1進入UIViewController1,單擊時單元格2進入UIViewController2 –

回答

0

您必須有一個單元標識符。在didselect方法中,你必須檢查哪個單元格被點擊,並且inprpare只需檢查你已經映射到的segue標識符並執行segue。