簡體   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