简体   繁体   English

我应该用什么来制作这种单元格,以便可以让每个单元格缝到不同的ViewController?

[英]What should I use to make this kind of cell, so I can get each of them to segue to different ViewController?

Here is what I want to do (UI is showing down below), I want to perform different segue when I taped different cell in it. 这是我想做的事情(UI在下面显示),当我在其中粘贴不同的单元格时,我想执行不同的搜索。 But I don't know what component I should use to get this done 但我不知道应该使用什么组件来完成此操作

I think to use the Collection View Controller, but it seems doest support static cells, I want to use Customized UIVIew to do this, but it couldn't be dragged to another VC in StoryBoard, should I adopt some sort of Protocols of something to do this? 我想使用Collection View Controller,但是它似乎不支持静态单元格,我想使用Customized UIVIew来做到这一点,但是如果我采用某种某种协议来将它拖到StoryBoard中的另一个VC上,做这个?

Please answer in Swift 请用Swift回答

UI页面


After been helped 经过帮助

Turns out I just need to show the ViewController and haven't need segue yet, so here is the code. 原来,我只需要显示ViewController而不需要segue,所以这里是代码。

let categories: [(name: String, pic: String, identifier: String)] = [
    ("人物",  "Wilson_head",      "CharactersVC"),
    ("动物",  "Pig",              "MobsVC"),
    ("植物",  "Bamboo_Patch",     "PlantsVC"),
    ("食谱",  "Crock_Pot_Build",  "RecipesVC")
]

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
    let currentCategory = categories[indexPath.row]
    let destVC: UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: currentCategory.identifier)
    navigationController!.pushViewController(destVC, animated: true)
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
    {
        if(indexPath.row == 0)
        {
            let objstory = self.storyboard?.instantiateViewController(withIdentifier: “your Story bord identifier”) as! Your View_ViewController


            self.navigationController?.pushViewController(objstory, animated: true)
        }


    }

Collection View Controller doesn't support static cell. Collection View Controller不支持静态单元格。 But you can add static cell programmatically. 但是您可以通过编程方式添加静态单元格。

  1. set your cell data and target(segue id) for each cell. 设置您的单元格数据和每个单元格的目标(segue ID)。 ex: 例如:

    cellData[0].segue = "segueToHuman"

    cellData[1].segue = "segueToAnimal"

  2. add segues depend on your view controller(not on cell) like below: 添加脚本取决于您的视图控制器(而不是单元格),如下所示:

create segue 创建segue

在此处输入图片说明

segue setting 情景设置

在此处输入图片说明

  1. perform particular segue in didSelectItemAt indexPath didSelectItemAt indexPath执行特定的segue

    let segueID = cellData[indexPath.row].segue performSegue(withIdentifier: segueID, sender: nil)

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

相关问题 如何在另一个 TabController 中选择 ViewController? - How can I segue to a ViewController in another TabController? 我如何使用uitableview单元执行segue - How can i use uitableview cell for performing segue 我有多个情节提要。 如何使用AppDelegate在另一个情节提要中打开另一个ViewController? (Segue) - I have multiple storyboards. How can I use AppDelegate to open another ViewController in another storyboard? (Segue) 我应该为 iOS 应用程序使用什么样的音频文件? - What kind of audio file should i use for iOS Apps? 我应该使用哪种应用程序内购买? - What kind of In-App purchase should I use? 我应该在这个简单的iPhone应用程序中使用哪种类型的ViewController - What type of ViewController should I use in this simple iPhone app 我可以将相同的detailViewController与不同的segue变量一起使用吗 - Can i use same detailedViewController with different segue variables 如何从tableviewcell进行筛选,并将每个单元格中的不同数据传递到下一个tableview? - How do I segue from a tableviewcell and pass different data from each cell to the next tableview? 如何从大小不同的情节提要中使用相同的ViewController? - How can I use the same ViewController from a storyboard with different sizes? 我可以为同一个 ViewController 使用不同的故事板设计吗 - Can I use different Storyboard Design for same ViewController
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM