不知道如何从我的自定义单元格(在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视图控制器
            // ...
        }
    }
}

相关内容

热门资讯

wpk德州ai辅助神器!wpk... wpk德州ai辅助神器!wpk有透视辅助吗,(wPk)本来有挂,软件教程(黑科技神器)1、在wpk德...
wpk德州透视外挂!wpk德州... wpk德州透视外挂!wpk德州透视外挂,(wpK)都是真的是有挂,AA德州教程(黑科技科技)该软件可...
AApoker透视辅助器安装教... AApoker透视辅助器安装教程!aapoker辅助器怎么用,(AApoker)总是存在有挂,专业教...
Wepoke黑科技设备!wep... Wepoke黑科技设备!wepoke透明挂哪里有,(WepOke)好像是有挂,我来教教你(黑科技辅助...
德扑ai助手!德扑ai智能机器... 德扑ai助手!德扑ai智能机器人代理,(德扑)竟然是真的有挂,详细教程(黑科技黑科技);一、德扑ai...
德扑之星ai代打风险分析!德扑... 德扑之星ai代打风险分析!德扑之星ai代打,(德扑之星)果然是真的有挂,力荐教程(黑科技插件)1)德...
德州ai购买!线上德州ai辅助... 德州ai购买!线上德州ai辅助,(德州ai)其实是有挂,揭秘教程(黑科技透视)1、很好的工具软件,可...
wepoke有没有挂!wepo... wepoke有没有挂!wepoke到底有没有挂,(we-poker)竟然真的有挂,科技教程(黑科技工...
AApoker辅助工具!aap... AApoker辅助工具!aapoker辅助实际测试,(AAPoker)原来真的有挂,力荐教程(黑科技...
微扑克ai软件!微扑克助手,(... 微扑克ai软件!微扑克助手,(微扑克)确实真的有挂,2025新版教程(黑科技透明挂)1、许多玩家不知...