UICollectoinViewCell 没有 present 成员(为了呈现另一个视图)?

The UICollectoinViewCell has no member of present (in order to present another view )?

我已经为我在我的应用程序中用于集合视图的自定义单元格创建了一个 class。在这个单元格中,我有一个按钮,我想将其从当前故事板引导至另一个故事板。所以我尝试使用 present 如下:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
            let cr = storyboard.instantiateViewController(withIdentifier: "test")
            self.present(cr, animated: true)

但是发件人有问题,在本例中是发件人自己。该错误表明 UICollectionViewCell 没有有意义的 present 成员。但是,我如何才能实现我的目标,因为我可能需要对 segus 使用相同的概念,以便将信息从一个故事板传输到另一个故事板?

您的问题的解决方案可以这样解决

在您的自定义 CollectionViewCell 中添加 Button 作为 IBOutlet

class CustomCollectionViewCell : UICollectionViewCell
{
    @IBOutlet weak var btnDemo: UIButton!
    //Otherstuff
}

并且在具有 CollectionViewViewController 中从 CustomCell 上的那个 UIButton 添加 IBAction 并且在 CellForRowAtIndexPath 中您需要添加标记到该按钮以识别您单击了哪个按钮,即

class ViewController : UIViewController
{
    @IBAction func btnButtonPressed(_ sender: Any) 
    {         
        let currentBtn = sender as UIButton
    } 
    func collectionView(collectionView: UICollectionView,
         cellForItemAtIndexPath indexPath: NSIndexPath) -> 
         UICollectionViewCell 
    {
       //Initialize Cell and other necessary stuff
       currentCell.btnDemo.tag = indexPath.row
    }