繁体   English   中英

按下indexPath单元格时如何导航或显示其他视图控制器

[英]how to navigate or show other view controller when indexPath cell pressed

我有2 cells一个集合视图。 所以默认情况下,第一个单元格将是0,1......而且我还有2 viewcontroller 分别命名为1. firstVC, 2. secondVC 我需要的是,当我点击单元格1时,它应该将firstVC显示为modal视图segue

就像当我按下第二个单元格一样,它应该显示第二个secondVC作为modal视图segue ..

如何做到这一点,在这里我可以打印我选择的单元格。 如何显示那个viewcontrollers?

   func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
        // You can use indexPath to get "cell number x", or get the cell like:
        let cell = collectionView.cellForItemAtIndexPath(indexPath)

    if((indexPath.row) == 0) {
        print("Layout 1 clicked")

    }
    else if((indexPath.row) == 1) {
        print("Layout 2 clicked")
    }
    else if((indexPath.row) == 2) {
        print("Layout 3 clicked")
    }
    else if((indexPath.row) == 3) {
        print("Layout 4 clicked")
    }


    }

请帮帮我...谢谢!

使用self.presentViewController(UIViewController, animated: Bool)或在界面生成器中添加segue,然后使用self.performSegueWithIdentifier(String, sender: AnyObject?)调用。 另外,在IB中添加segue时,请确保将其更改为“模态显示”。

暂无
暂无

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

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