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

相关内容

热门资讯

解谜透视!拱趴大菠萝万能挂图解... 解谜透视!拱趴大菠萝万能挂图解,微乐小程序辅助器代理,教材教程(有挂解惑)-哔哩哔哩1、玩家可以在拱...
辅助透视!wepoker透视脚... 辅助透视!wepoker透视脚本下载,微乐山西小程序破解器,技法教程(详细教程)-哔哩哔哩1、玩家可...
详细透视!wepoker辅助器... 您好,wepoker辅助器是真的吗这款游戏可以开挂的,确实是有挂的,需要了解加去威信【4852750...
必备透视!wepoker有辅助... 必备透视!wepoker有辅助工具吗,微乐自建房脚本免费下载入口,资料教程(有挂讲解)-哔哩哔哩1、...
辅助透视!aapoker怎么拿... 辅助透视!aapoker怎么拿好牌,微乐房间辅助工具在哪下载,要领教程(今日头条)-哔哩哔哩1、每一...
分享透视!德州圈脚本,微乐四川... 分享透视!德州圈脚本,微乐四川亲友圈辅助器,烘培教程(有挂秘诀)-哔哩哔哩1、德州圈脚本辅助器安装包...
解密透视!wpk透视插件,微乐... 解密透视!wpk透视插件,微乐广西小程序脚本,技法教程(有挂总结)-哔哩哔哩wpk透视插件透视方法中...
详情透视!pokemmo辅助工... 详情透视!pokemmo辅助工具,微信小程序微乐辅助器苹果,方式教程(真实有挂)-哔哩哔哩;1、po...
解迷透视!aapoker安装包... 解迷透视!aapoker安装包怎么使用,微信小程序微乐房间怎么辅助,妙计教程(真的有挂)-哔哩哔哩1...
推荐透视!wepoker怎么下... 推荐透视!wepoker怎么下载游戏,微信微乐辅助脚本平台,课程教程(有挂详情)-哔哩哔哩1、游戏颠...