多个UICollectionViewCells用于分隔UIViewController

时间:2014-02-10 18:54:44

标签: uicollectionview uistoryboard segue uistoryboardsegue uicollectionviewcell

我有两个单独的UICollectionViewCells,标识符为MY_CELL和MY_CELL_2

然后我写了这个:

#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];



    }

然后我有两个UIVC,UIVC1和UIVC2我希望MY_CELL转到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可见。

任何人都知道我做错了什么以及为什么我看不到第二个牢房?

1 个答案:

答案 0 :(得分:0)

您必须为单元格设置一个标识符。在didselect方法中,你必须检查单击了哪个单元格并且inprpare segue只检查你映射到的segue标识符并执行segue。