不知道如何从我的自定义单元格(在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、点...
4分钟脚本!微乐小程序免费黑科... 4分钟脚本!微乐小程序免费黑科技,微乐河南家乡麻将辅助脚本(开挂)竟然存在有挂(2026)1、起透看...
透视美元局!微乐小程序免费黑科... 透视美元局!微乐小程序免费黑科技,小程序微乐辅助器ios(透视)一直有挂(哔哩哔哩)1、下载好微乐小...
第2分钟辅助!微乐小程序免费黑... 第2分钟辅助!微乐小程序免费黑科技,微信小程序游戏修改器(开挂)确实是有挂(2026)1、实时微乐小...
2026版复盘!微乐小程序免费... 2026版复盘!微乐小程序免费黑科技,微乐小程序脚本(透视)果然真的是有挂(哔哩哔哩)1、每一步都需...
五分钟透视!微乐小程序黑科技,... 五分钟透视!微乐小程序黑科技,微信小程序微乐辅助器破解版(开挂)真是是有挂(2026)1、微乐小程序...
透视工具!微乐小程序免费黑科技... 透视工具!微乐小程序免费黑科技,小程序微乐游戏辅助器(透视)都是是有挂(哔哩哔哩)1.小程序微乐游戏...
第八分钟神器!微乐小程序黑科技... 第八分钟神器!微乐小程序黑科技,微乐家乡app下载(开挂)真是存在有挂(2026)1、下载好微乐小程...
第十分钟安装!微乐小程序黑科技... 第十分钟安装!微乐小程序黑科技,微信卡五星小程序辅助(开挂)果然是真的挂(2026)暗藏猫腻,小编详...
连日来!微乐小程序免费黑科技,... 连日来!微乐小程序免费黑科技,小程序微乐辅助器免费版(透视)原来有挂(哔哩哔哩)运小程序微乐辅助器免...