簡體   English   中英

如何從集合視圖中打開視圖控制器?

[英]how open viewcontroller from collection view?

我是 ios 開發的新手,我想知道如何從集合視圖中打開一個新的視圖控制器。

我有我的收藏視圖,現在我想在按下圖像 1 時打開我的 viewcontroller 顏色紫色,並在按下圖像 2 時打開 mu viewcontroller 顏色青色。

我想知道用戶點擊了什么圖像然后顯示視圖控制器

我添加一個圖像。

在此處輸入圖像描述

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  let secondVC = self.storyboard?.instantiateViewController(withIdentifier: "SecondView") as! SecondViewController
  secondVC.modalPresentationStyle = .overCurrentContext
/// if use navigation controller
  self.navigationController?.pushViewController(secondVC, animated: true)
/// if use viewController
self.present(secondVC, animated: true, completion: nil)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM