不知道如何从我的自定义单元格(在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控制牌是真的吗,解说技巧(有挂总结);1、点击下载安装,...
科技介绍!青龙辅助最新下载,p... 科技介绍!青龙辅助最新下载,pokeplus脚本,切实教程(有挂方法);1、让任何用户在无需AI插件...
盘点一款!陕西挖坑辅助,new... 【福星临门,好运相随】;盘点一款!陕西挖坑辅助,newpoker怎么安装脚本,科技教程(确实有挂);...
必备辅助推荐!家乡大二有没有辅... 必备辅助推荐!家乡大二有没有辅助,来玩app破解,必备教程(有挂神器);1、这是跨平台的家乡大二有没...
攻略讲解!微信小程序辅助器免费... 攻略讲解!微信小程序辅助器免费2.0苹果版,wepoker透视脚本免费下载,揭秘攻略(有挂详细);作...
发现玩家!钱塘十三水辅助,we... 发现玩家!钱塘十三水辅助,wepoker私人定制透视,2025新版技巧(有挂教程);致您一封信;亲爱...
来一盘!雷霆辅助器,德普之星透... 来一盘!雷霆辅助器,德普之星透视辅助,介绍教程(有挂攻略)是一款可以让一直输的玩家,快速成为一个“必...
9分钟了解!决战卡五星辅助器下... 9分钟了解!决战卡五星辅助器下载,aapoker透视脚本下载,德州论坛(有挂秘诀);决战卡五星辅助器...
玩家必备攻略!雀神挂件价格辅助... 玩家必备攻略!雀神挂件价格辅助开挂,德普之星透视辅助软件是真的吗,攻略方法(有挂技术)是一款可以让一...