不知道如何从我的自定义单元格(在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辅助哪里买,w... 解迷透视!wpk辅助哪里买,wepoker免费脚本咨询,经验教程(真实有挂)-哔哩哔哩1、该软件可以...
解谜透视!聚星ai辅助工具激活... 解谜透视!聚星ai辅助工具激活码!真是是有辅助app(证实有挂)-哔哩哔哩该软件可以轻松地帮助玩家将...
专业透视!wpk透视工作室,w... 专业透视!wpk透视工作室,wepoker辅助是真的吗,举措教程(有挂详情)-哔哩哔哩1、wepok...
教你透视!德州局怎么透视!果然... 教你透视!德州局怎么透视!果然真的是有辅助工具(有挂细节)-哔哩哔哩1、德州局怎么透视公共底牌简单,...
详情透视!如何下载wepoke... 详情透视!如何下载wepoker安装包,wepoker透视有没有,秘籍教程(果真有挂)-哔哩哔哩1、...
推荐透视!we poker免费... 推荐透视!we poker免费辅助器!都是是真的有辅助app(有挂教学)-哔哩哔哩1、让任何用户在无...
解密透视!约局吧怎么看有没有挂... 解密透视!约局吧怎么看有没有挂,红龙poker辅助器免费观看,方案教程(有挂方略)-哔哩哔哩;1、每...
详情透视!红龙poker有辅助... 详情透视!红龙poker有辅助吗!竟然真的是有辅助插件(有挂方略)-哔哩哔哩1、操作简单,无需红龙p...
有挂透视!hhpoker到底可... 有挂透视!hhpoker到底可以作必弊吗,德州局hhpoker,阶段教程(有挂规律)-哔哩哔哩1、h...
解谜透视!pokemmo手机版... 解谜透视!pokemmo手机版脚本!总是是有辅助软件(有挂分享)-哔哩哔哩1、完成pokemmo手机...