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

相关内容

热门资讯

玩家亲测!pokerworld... 玩家亲测!pokerworld修改器(辅助挂)本来是真的有挂(有挂详情辅助器)1、脚本辅助下载、免费...
程序员教你!约局吧德州真的存在... 程序员教你!约局吧德州真的存在透视吗(辅助挂)都是是有挂(有挂技术辅助软件)1、首先打开辅助器下载最...
盘点十款!aapoker透视脚... 盘点十款!aapoker透视脚本下载(辅助挂)一贯有挂(存在有挂辅助方法)1、实时透视辅助更新:用户...
安装程序教程!wepoker公... 安装程序教程!wepoker公共底牌(辅助挂)总是真的有挂(有挂详情辅助软件)1、有没有辅助教程、有...
免费测试版!wepoker好友... 免费测试版!wepoker好友局透视(辅助挂)真是是有挂(有挂规律辅助方法)1、玩家可以在线上大神俱...
实操分享!wepoker亲友圈... 实操分享!wepoker亲友圈有用吗(辅助挂)总是真的是有挂(有挂分享辅助工具)1、玩家可以在线上大...
研究成果!hhpoker真的有... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏中打...
推荐一款!wepoker插件下... 推荐一款!wepoker插件下载(辅助挂)竟然有挂(真是有挂辅助工具)1、这是跨平台的轻量版有透视,...
分享一款!德州透视是真的吗(辅... 分享一款!德州透视是真的吗(辅助挂)一直真的是有挂(有挂详细辅助教程)小薇(辅助器软件下载)致您一封...
玩家必用!wepoker辅助透... 玩家必用!wepoker辅助透视软件(辅助挂)好像真的是有挂(今日头条辅助教程)1、玩家必用!wep...