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

相关内容

热门资讯

详细透视!pokemmo手机版... 详细透视!pokemmo手机版脚本免费!其实是有辅助插件(揭秘有挂)-哔哩哔哩1、这是跨平台的pok...
解迷透视!xpoker辅助怎么... 解迷透视!xpoker辅助怎么用!竟然存在有辅助插件(真的有挂)-哔哩哔哩1.xpoker辅助怎么用...
科普透视!约局吧开挂神器是真的... 科普透视!约局吧开挂神器是真的吗!原来是真的有辅助软件(有挂解惑)-哔哩哔哩1、任何约局吧开挂神器是...
有挂透视!xpoker辅助工具... 有挂透视!xpoker辅助工具!好像真的有辅助工具(详细教程)-哔哩哔哩1、打开软件启动之后找到中间...
解谜透视!epoker有透视吗... 解谜透视!epoker有透视吗!都是是真的有辅助app(有挂技术)-哔哩哔哩1)epoker有透视吗...
详情透视!poker红龙辅助!... 详情透视!poker红龙辅助!一直真的有辅助教程(揭秘有挂)-哔哩哔哩1、操作简单,无需poker红...
总结透视!pokemmo脚本!... 总结透视!pokemmo脚本!总是存在有辅助app(有人有挂)-哔哩哔哩1、pokemmo脚本破解器...
推荐透视!werplan怎么作... 推荐透视!werplan怎么作必弊!切实一直总是有辅助技巧(有挂秘诀)-哔哩哔哩1、werplan怎...
解密透视!大菠萝789辅助器下... 解密透视!大菠萝789辅助器下载!真是一直总是有辅助软件(有挂透视)-哔哩哔哩1、大菠萝789辅助器...
揭露透视!聚星ai辅助工具激活... 揭露透视!聚星ai辅助工具激活码!竟然真的有辅助app(有挂猫腻)-哔哩哔哩一、聚星ai辅助工具激活...