不知道如何从我的自定义单元格(在UICollectionView中)执行Segue到Player(ViewController)。
创始人
2025-01-12 03:30:31
0

在你的自定义UICollectionViewCell中添加tap手势识别器:

class CustomCell: UICollectionViewCell {
    // 添加你的UI元素
    // ...

    weak var parentViewController: UIViewController?

    override init(frame: CGRect) {
        super.init(frame: frame)
        addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(cellTapped)))
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    @objc func cellTapped() {
        parentViewController?.performSegue(withIdentifier: "YourSegueIdentifier", sender: self)
    }
}

然后,在你的UICollectionViewDataSource协议的cellForItemAt方法中设置parentViewController:

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "YourCellIdentifier", for: indexPath) as! CustomCell
    cell.parentViewController = self
    return cell
}

最后,在你的UIViewController(即Player)中使用prepareForSegue方法传递数据:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "YourSegueIdentifier" {
        if let cell = sender as? CustomCell {
            let indexPath = collectionView.indexPath(for: cell)
            // 在这里传递你的数据到Player视图控制器
            // ...
        }
    }
}

相关内容

热门资讯

外挂机巧!红龙poker辅助平... 您好,红龙poker辅助平台这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】...
外挂手段!德普之星有透视辅助吗... 外挂手段!德普之星有透视辅助吗,拱趴大菠萝挂怎么安装-确实是真的有辅助工具(哔哩哔哩)1、操作简单,...
外挂烘培!aa poker辅助... 外挂烘培!aa poker辅助,德州私人局脚本-其实真的有辅助方法(哔哩哔哩)1、上手简单,内置详细...
外挂指南书!sohoo pok... 外挂指南书!sohoo poker辅助器,红龙poker辅助平台-本来是真的有辅助技巧(哔哩哔哩)一...
外挂阶段!哈糖大菠萝软件下载,... 外挂阶段!哈糖大菠萝软件下载,fishpoker透视-切实一直总是有辅助软件(哔哩哔哩)在进入哈糖大...
外挂手筋!拱趴大菠萝十三水作必... 外挂手筋!拱趴大菠萝十三水作必弊,sohoopoker辅助-一直存在有辅助神器(哔哩哔哩)一、拱趴大...
外挂步骤!wepoker安装教... 外挂步骤!wepoker安装教程,佛手在线大菠萝为什么都输-果然真的有辅助软件(哔哩哔哩)1)佛手在...
外挂演示!菠萝辅助器免费版的特... 外挂演示!菠萝辅助器免费版的特点,约局吧作必弊脚本-好像有辅助工具(哔哩哔哩);1、超多福利:超高返...
外挂指引!哈糖大菠萝免费辅助器... 外挂指引!哈糖大菠萝免费辅助器,pokermaster破解版-果然存在有辅助脚本(哔哩哔哩)哈糖大菠...
外挂步骤!hardrock透视... 外挂步骤!hardrock透视工具,竞技联盟破解版最新版-竟然有辅助软件(哔哩哔哩)所有人都在同一条...