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

相关内容

热门资讯

带你了解辅助!来来台安麻将ai... 本地部署 AI 黑科技工具迎来新版本,不用上传文件到云端就能完成来来台安麻将解析、 AI 处理、来来...
WPK俱乐部透视挂操作!wep... WPK俱乐部透视挂操作!wepoker私局代打,红龙扑克ai多功能透视挂脚本;1、wepoker私局...
WPK安装辅助器法门!we p... WPK安装辅助器法门!we poker插件,德扑之星ai多功能辅助器神器;运we poker插件辅助...
系统教程辅助挂!七色城ai辅助... 系统教程辅助挂!七色城ai辅助挂多功能插件,真是是有辅助挂教程法子是一款可以让一直输的玩家,快速成为...
WPK安卓辅助器学习!wepo... WPK安卓辅助器学习!wepoker免费透视脚本,德州扑克ai多功能辅助器攻略1、wepoker免费...
玩家必备科技!辅助器!闽乐ai... 玩家必备科技!辅助器!闽乐ai辅助器多功能插件,都是是有辅助器教程法门是一款可以让一直输的玩家,快速...
WPK透视辅助器攻略!wepo... WPK透视辅助器攻略!wepoker手机版辅助,AApokerai多功能辅助器方法1、wepoker...
今日公布开挂!伊春麻将ai开挂... 伊春麻将AI 游戏攻略黑科技上线本地缓存功能,离线查阅能力开挂。提前下载对应游戏攻略数据包,断网状态...
WPK俱乐部辅助指南!wepo... WPK俱乐部辅助指南!wepoker俱乐部辅助,德州扑克ai多功能辅助技巧1、在wepoker俱乐部...
总算清楚!辅助挂!华夏娱乐ai... 总算清楚!辅助挂!华夏娱乐ai辅助挂多功能插件,一向存在有辅助挂助手手段主打本地运行的 AI 黑科技...