不知道如何从我的自定义单元格(在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、很好的工具软件,可以...
曝光透视!werplan辅助软... 曝光透视!werplan辅助软件,德州来玩辅助器(透视)一直一直都是有辅助app(哔哩哔哩)德州来玩...
关于透视!约局吧德州真的有透视... 关于透视!约局吧德州真的有透视挂吗,哈糖大菠萝攻略(透视)都是存在有辅助软件(哔哩哔哩)1、每一步都...
辅助透视!xpoker辅助神器... 辅助透视!xpoker辅助神器,红龙poker辅助平台(透视)一直有辅助软件(哔哩哔哩)运红龙pok...
普及透视!佛手大菠萝辅助,德州... 普及透视!佛手大菠萝辅助,德州局透视(透视)本来真的是有辅助脚本(哔哩哔哩)1、点击下载安装,佛手大...
解谜透视!德州透视是真的假的,... 解谜透视!德州透视是真的假的,哈糖大菠萝可以开挂吗(透视)一直一直总是有辅助神器(哔哩哔哩)1、不需...
详细透视!pokerworld... 详细透视!pokerworld辅助器,pokemmo手机脚本(透视)都是真的是有辅助教程(哔哩哔哩)...
必备透视!拱趴游戏破解器,xp... 必备透视!拱趴游戏破解器,xpoker辅助工具(透视)本来一直总是有辅助技巧(哔哩哔哩)1、玩家可以...
普及透视!werplan怎么作... 普及透视!werplan怎么作必弊,pokemmo手机脚本(透视)总是是有辅助插件(哔哩哔哩)一、w...
必备透视!pokernow辅助... 必备透视!pokernow辅助控制,约局吧辅助器(透视)真是存在有辅助软件(哔哩哔哩)1、poker...