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

相关内容

热门资讯

透视黑科技!wepoker底牌... 透视黑科技!wepoker底牌透视脚本app,wepoker祈福有用吗(详细辅助技巧教程);1、让任...
wpk辅助挂!aapoker有... wpk辅助挂!aapoker有网页版吗(透视)本然真的有挂(详细辅助透牌教程);致您一封信;亲爱wp...
透视科技!德普之星透视辅助软件... 透视科技!德普之星透视辅助软件,购买的wpk辅助在哪里下载(详细辅助安装教程)1、德普之星透视辅助软...
wepower辅助器!微扑克有... wepower辅助器!微扑克有辅助挂吗(透视)都是是真的有挂(详细辅助揭秘攻略);小薇(透视辅助)致...
德扑ai助手!德州软件后台控制... 德扑ai助手!德州软件后台控制(透视)果然是真的有挂(详细辅助系统教程)1.德扑ai助手 ai辅助创...
透视总结!智星菠萝辅助器,德普... 透视总结!智星菠萝辅助器,德普之星私人局透视(详细辅助必备教程)1、下载好智星菠萝辅助器辅助软件之后...
德州之星插件!aapoker是... 德州之星插件!aapoker是正规的吗(透视)原生有挂(详细辅助可靠技巧)1、很好的工具软件,可以解...
透视有挂!德普之星辅助功能如何... 透视有挂!德普之星辅助功能如何设置,hhpoker有后台操控吗(详细辅助曝光教程);1、德普之星辅助...
wepoke ai辅助!gg扑... wepoke ai辅助!gg扑克为什么赢不了(透视)固有真的是有挂(详细辅助专业教程)1、不需要AI...
透视挂透视!德普之星透视辅助软... 透视挂透视!德普之星透视辅助软件是真的吗,poker world辅助器(详细辅助黑科技教程)1、构建...