Ios UICollectionView每个UICollectionViewCell的不同阶段
我有一个动态加载单元格的UICollectionView,但我想在推单元格时打开一个不同的UIViewController。 例如: -cell1打开UIViewController1 -cell2打开UIViewController2 -单元格3打开UIViewController3Ios UICollectionView每个UICollectionViewCell的不同阶段,ios,objective-c,iphone,Ios,Objective C,Iphone,我有一个动态加载单元格的UICollectionView,但我想在推单元格时打开一个不同的UIViewController。 例如: -cell1打开UIViewController1 -cell2打开UIViewController2 -单元格3打开UIViewController3 有人知道吗,如果可能的话?以编程方式进行,在UICollectionViewDelegate方法didSelectItemAtIndexPath UIViewController *c = [self.story
有人知道吗,如果可能的话?以编程方式进行,在
UICollectionViewDelegate
方法didSelectItemAtIndexPath
UIViewController *c = [self.storyboard instantiateViewControllerWithIdentifier:[NSString stringWithFormat:@"%li",(long)indexPath.row]];
[self.navigationController pushViewController:c animated:YES];
//or however you a moving to next viewcontroller
确保您的ViewController具有正确命名的标识符以匹配单元格以编程方式执行此操作,类似于
UICollectionViewDelegate
方法didSelectItemAtIndexPath
UIViewController *c = [self.storyboard instantiateViewControllerWithIdentifier:[NSString stringWithFormat:@"%li",(long)indexPath.row]];
[self.navigationController pushViewController:c animated:YES];
//or however you a moving to next viewcontroller
确保ViewController具有与单元格匹配的正确命名标识符,您需要创建一个从保存集合视图(非单元格)的视图控制器到目标视图控制器的序列,例如:
UICollectionViewController -> UIViewController1
UICollectionViewController -> UIViewController2
//...etc
记住给每个序列添加标识符
在代码覆盖UICollectionViewDelegate
方法中
collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
在该方法中,检查哪个单元格被点击(indexPath),如果是cell1,则使用正确的标识符调用segue:
performSegueWithIdentifier("goToVC1Identifier", sender: nil)
您需要创建从保存集合视图(非单元)的视图控制器到目标视图控制器的分段,例如:
UICollectionViewController -> UIViewController1
UICollectionViewController -> UIViewController2
//...etc
记住给每个序列添加标识符
在代码覆盖UICollectionViewDelegate
方法中
collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath)
在该方法中,检查哪个单元格被点击(indexPath),如果是cell1,则使用正确的标识符调用segue:
performSegueWithIdentifier("goToVC1Identifier", sender: nil)
您需要在collectionView的委托的
-(void)collectionView:(UICollectionView*)collectionView didSelectItemAtIndexPath:(NSIndexPath*)indexPath
中手动执行序列。您需要在-(void)collectionView:(UICollectionView*)collectionView didSelectItemAtIndexPath中手动执行序列:(NSIndexPath*)collectionview委托的indexPath