我在collectionView中有一个collectionView,并且我希望能够在第二个collectionView中选择一个单元格以对另一个ViewController进行选择。
当前,当我选择一个单元格时,收到以下消息: “接收器...没有标识为'ToVC2'的标记。”
但是,我已经从其他UIButton中使用了这个segue / identifier,它可以正常工作。
我有两个ViewController:ViewController1和ViewController2。
在ViewController1上,有一个具有垂直滚动的collectionView(“ categoryCollectionView”)。
在categoryCollectionView中,还有另一个collectionView(“ eventCollectionView”)可以水平滚动。
两个collectionViews已针对numberOfItemsInSection和cellForItemAt设置并正常工作。现在,我希望能够在eventCollectionView中选择一个单元,并引起从ViewController1到ViewController2的选择。
我在ViewController1中添加了一个函数:
func segueToViewController2(event: Event){
performSegue(withIdentifier: "ToVC2", sender: event)
}
在eventCollectionView的didSelectItemAt中,我尝试了以下操作:
var viewController1: ViewController1? = ViewController1()
viewController1.segueToViewController2(event: eventSelected)
当我选择一个单元格时,出现以下错误信息:
'Receiver()没有标识为'ToVC2'的序列
但是,如果从ViewController1上的常规UIButton调用此函数,则该函数可以正确执行segue(因此,我知道问题不在于没有segue /标识符错误。)我认为问题在于该函数正在被调用从collectionView内的collectionView中获取。
请帮忙!!!!!
答案 0 :(得分:0)
我相信问题在于,当您调用.css("width")
时,您正在初始化var viewController1: ViewController1? = ViewController1()
的新实例。这可能不是您的意思。根据您所说的内容,您应该在创建的集合视图的层次结构中向下传递一个引用,以便您的didSelect可以在ViewController1
的原始实例上调用segue函数。理想情况下,您将使用委托等设计模式来完成此操作。