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

相关内容

热门资讯

8分钟下载!微乐小程序免费黑科... 8分钟下载!微乐小程序免费黑科技,微乐智能辅助app(开挂)好像存在有挂(2026)进入游戏-大厅左...
长期以来!微乐小程序黑科技,微... 长期以来!微乐小程序黑科技,微乐自建房免费黑科技下载苹果(透视)竟然有挂(哔哩哔哩)1、任何微乐自建...
第三分钟下载!微乐小程序免费黑... 第三分钟下载!微乐小程序免费黑科技,微乐游戏小程序脚本(开挂)真是是真的挂(2026)1、下载好微乐...
透视肯定!微乐小程序黑科技,微... 透视肯定!微乐小程序黑科技,微乐家乡自建房辅助app(透视)确实真的是有挂(哔哩哔哩)1、打开软件启...
3分钟插件!微乐小程序黑科技,... 3分钟插件!微乐小程序黑科技,微乐斗地主有挂吗(开挂)竟然存在有挂(2026)1、微乐小程序黑科技辅...
透视安卓版!微乐小程序黑科技,... 透视安卓版!微乐小程序黑科技,微乐江西小程序辅助(透视)确实真的有挂(哔哩哔哩)1、点击下载安装,微...
五分钟下载!微乐小程序黑科技,... 五分钟下载!微乐小程序黑科技,微乐广西小程序插件(开挂)确实真的是有挂(2026)1、点击下载安装,...
黑科技教程!微乐小程序免费黑科... 黑科技教程!微乐小程序免费黑科技,微信小程序微乐辅助器免费下载(透视)其实真的有挂(哔哩哔哩)1、超...
第1分钟辅助!微乐小程序黑科技... 第1分钟辅助!微乐小程序黑科技,微乐自建房辅助软件(开挂)竟然是真的挂(2026)1、第1分钟辅助!...
透视插件!微乐小程序黑科技,微... 透视插件!微乐小程序黑科技,微乐贵阳足鸡麻将开挂(透视)竟然是真的挂(哔哩哔哩)1、实时微乐贵阳足鸡...