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

相关内容

热门资讯

透牌教程!wepoke游戏辅助... 透牌教程!wepoke游戏辅助工具(wepoke辅助挂)WepOke(一贯真的有挂);科技详细教程小...
分享实测!胡乐辅助器免费版(辅... 分享实测!胡乐辅助器免费版(辅助挂)竟然有挂(2025已更新)(哔哩哔哩)1、玩家可以在胡乐辅助器免...
微扑克辅助机器人!wpk微扑克... 微扑克辅助机器人!wpk微扑克辅助透视,微扑克ai辅助工具,细节揭秘(有挂技巧);微扑克是一种具有地...
科技教程!wepoke app... 科技教程!wepoke app系统规律(wepoke辅助插件)WEPoke(原来真的有挂);原来确实...
揭秘!哥哥跑得快怎么赢(透明挂... 揭秘!哥哥跑得快怎么赢(透明挂)一贯是真的有挂(2026已更新)(哔哩哔哩);一、哥哥跑得快怎么赢软...
微扑克辅助机器人!微扑克机制技... 1、微扑克辅助机器人!微扑克机制技巧,微扑克真的有挂,辅助教程(有挂详情);详细教程。2、微扑克透视...
WePoKe透视挂!we po... 1、WePoKe透视挂!we poke软件免费版(透视辅助)wEPOKE(原来真的有挂)(UU po...
一分钟了解!开心武汉花可以开挂... 一分钟了解!开心武汉花可以开挂吗(辅助挂)切实有挂(2020已更新)(哔哩哔哩)1.开心武汉花可以开...
微扑克有辅助挂!微扑克俱乐部设... 微扑克有辅助挂!微扑克俱乐部设置,微扑克有稳赢的打法(竟然真的是有挂)1、许多玩家不知道微扑克辅助软...
wepoke辅助有挂!用ai外... wepoke辅助有挂!用ai外 挂打德州有用(辅助透视)WEPOke(其实真的有挂)1、玩家可以在W...