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

相关内容

热门资讯

最新通报!wepoker辅助器... 最新通报!wepoker辅助器下载(辅助挂)其实有挂(真的有挂辅助插件)1、上手简单,内置详细流程视...
我来分享!wepoker网页版... 我来分享!wepoker网页版透视方法(辅助挂)本来是真的有挂(有挂教程辅助技巧)1、上手简单,内置...
总算清楚!wejoker辅助软... 总算清楚!wejoker辅助软件价格(辅助挂)都是有挂(有挂方法辅助app)1、该软件可以轻松地帮助...
教程攻略!哈糖大菠萝万能挂(辅... 教程攻略!哈糖大菠萝万能挂(辅助挂)真是存在有挂(真是有挂辅助教程)1、首先打开辅助器下载最新版本,...
科技分享!德普之星透视(辅助挂... 科技分享!德普之星透视(辅助挂)果然真的有挂(有挂细节辅助工具)1、辅助器安装包、辅助器2、分享自己...
发现一款!有没有人wepoke... 发现一款!有没有人wepoker(辅助挂)确实有挂(有挂规律辅助工具)1、进入到是否有挂之后,能看到...
科普攻略!wepoker透视是... 科普攻略!wepoker透视是真的吗(辅助挂)一贯真的是有挂(果真有挂辅助软件)1、点击下载安装,脚...
揭秘攻略!wepoker代打辅... 揭秘攻略!wepoker代打辅助(辅助挂)总是是有挂(讲解有挂辅助软件)1、免费脚本咨询教程、免费脚...
玩家必看攻略!wepoker免... 玩家必看攻略!wepoker免费脚本弱密码(辅助挂)一直真的是有挂(有挂方法辅助脚本)1、任何透视是...
大家学习交流!hhpoker哪... 大家学习交流!hhpoker哪个俱乐部靠谱(辅助挂)都是是有挂(有挂教程辅助插件)1、许多玩家不知道...