[英]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回答
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. 但是您可以通过编程方式添加静态单元格。
set your cell data and target(segue id) for each cell. 设置您的单元格数据和每个单元格的目标(segue ID)。 ex: 例如:
cellData[0].segue = "segueToHuman"
cellData[1].segue = "segueToAnimal"
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.