简体   繁体   English

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

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

i have one collection view with 2 cells . 我有2 cells一个集合视图。 So by default first cell will be 0,1...... And i also have 2 viewcontroller . 所以默认情况下,第一个单元格将是0,1......而且我还有2 viewcontroller Named 1. firstVC, 2. secondVC . 分别命名为1. firstVC, 2. secondVC What i need is, when i tap cell 1 it should show the firstVC as a modal view segue . 我需要的是,当我点击单元格1时,它应该将firstVC显示为modal视图segue

same like when i press second cell, it should show the secondVC as a modal view segue .. 就像当我按下第二个单元格一样,它应该显示第二个secondVC作为modal视图segue ..

How to do that, here i can print which cell i am selecting. 如何做到这一点,在这里我可以打印我选择的单元格。 How to show that viewcontrollers ?? 如何显示那个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")
    }


    }

please help me out...Thanks !! 请帮帮我...谢谢!

Use self.presentViewController(UIViewController, animated: Bool) or add segue in the Interface Builder and call it using self.performSegueWithIdentifier(String, sender: AnyObject?) . 使用self.presentViewController(UIViewController, animated: Bool)或在界面生成器中添加segue,然后使用self.performSegueWithIdentifier(String, sender: AnyObject?)调用。 Also when adding segue in the IB make sure to change it to "present modally" if you need to. 另外,在IB中添加segue时,请确保将其更改为“模态显示”。

暂无
暂无

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

相关问题 按下导航控制器后退按钮时如何导航到其他View Controller? - How to navigate to some other View Controller when Navigation Controller back button is pressed? 如何将集合视图单元格的indexPath传递给另一个视图控制器 - How to pass a collection view cell's indexPath to another view controller 如何从一个视图控制器导航到另一个 - How to navigate From one view controller to other 当按下表格单元格时,将视图加载到导航视图控制器中 - Load view into navigation view controller when table cell is pressed 根据上一个按下的按钮,在下一个视图控制器中显示其他数组 - Show other array in next view controller depending on button pressed in previous 滑动单元格时,有没有一种方法可以从tableViewCell导航到另一个视图控制器? - Is there a way to navigate from a tableViewCell to another view controller when a cell is swiped? 添加/删除单元格时的集合视图列表单元格,如何更新单元格的indexPath? - collection view list cell when the cell is added / deleted, how to update the indexPath of the cell? 当按下其他视图 controller 中的按钮时,视图 controller 中的点击手势导致视图 controller 的打开延迟 - Tap gesture in a view controller causing delay in opening of the view controller when a button in other view controller is pressed 按下选项卡栏项时如何显示警报视图,以及在其他目标中使用时如何忽略它? - How to show alert view when tab bar item is pressed and how to ignore it when used in a other target? Swift:如何获取表行单元格(indexPath)并从详细视图控制器的数据模型中加载它? - Swift: How to get the table row cell (indexPath) and load it from the data model in detail view controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM