简体   繁体   English

集合查看不同的单元格选择

[英]CollectionView different cell selection

I have a basic UICollectionView set up with 5 version of the cell. 我有一个基本的UICollectionView设置了5个版本的单元格。 The cells populate fine. 细胞填充良好。 What I want to do is have each version segue to a certain view in the Storyboard (a view which I have given an ID). 我想做的是让每个版本都链接到情节提要中的某个视图(该视图已指定ID)。 Is there a way to do this? 有没有办法做到这一点? I have this code which counts the number of items in the controller, however, I will always know and control how many items are in it: 我有这段代码可以计算控制器中的项目数,但是,我将始终知道并控制其中的项目数:

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return videoList.count;

Is there some sort of switch I can use to have the first cell go to one UIViewController, and have the second go another? 我可以使用某种开关将第一个单元格转到一个UIViewController,将第二个单元格转到另一个UIViewController吗? Thanks 谢谢

You can use the indexPath.item as the switch. 您可以将indexPath.item用作开关。 In collectionView:didSelectItemAtIndexPath:, put in if-else statements (or a switch statement) to go to different controllers based on the indexPath.item of the cell you selected. 在collectionView:didSelectItemAtIndexPath:中,放入if-else语句(或switch语句)以根据所选单元格的indexPath.item转到不同的控制器。

You should be able to control this in your UICollectionViewDelegate class, specifically the collectionView:didSelectItemAtIndexPath: method. 您应该能够在UICollectionViewDelegate类中进行控制,特别是collectionView:didSelectItemAtIndexPath:方法。 In here you can use the indexPath.item to determine which cell they touched, then call a [self performSegueWithIdentifier:sender:] to control where in the storyboard it goes next. 在这里,您可以使用indexPath.item确定他们触摸了哪个单元格,然后调用[self performSegueWithIdentifier:sender:]来控制下一步在情节提要中的位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM