gpt4 book ai didi

swift - 从自定义表格 View 单元格中使用 Storyboard 序列

转载 作者:行者123 更新时间:2023-11-30 10:42:41 25 4
gpt4 key购买 nike

大家!

在我的主 Controller (MainController.swift)中,我有带有自定义 TableView 单元格的 TableView (带有 xlb、TableViewCell.swift 和 TableViewCell.xlb 的自定义类)。

在 Storyboard中,我创建了从主 Controller 到其他 View Controller (PromoViewController.swift)的segue。

现在我的决定是:在 TableViewCell 类中,我向某些单元格添加点击手势,并调用发布通知的函数。在 MainViewController 中,我添加了观察者,当我点击单元格代码时可以工作,但我在控制台中收到警告“...其 View 不在窗口层次结构中”

最佳答案

在单元格中包含一个闭合件。

您的 cell.swift

var didTap(() -> ())?

在单元格中出列时:

let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! Cell


cell.didTap = {
//perform segue here
}

从单元格调用关闭,例如当您希望发生转场时单击按钮。

didTap?()

关于swift - 从自定义表格 View 单元格中使用 Storyboard 序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56458881/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com