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

标签 swift

大家!

在我的主 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/

相关文章:

ios - Swift 扩展类型约束

json - 如何在便利初始化程序中检查 Swift 中的 JSON nil

ios - 如何使用 IOS、Xcode 和 Swift 将 Moltin 更新到 v2?

swift - 如何覆盖 SKScene init(fileNamed : fileNamed)

ios - 使用 UICollectionView 的过渡传递数据

Swift 使用未声明的类型'...ViewController'

ios - 在dismissViewController回调中刷新presentingViewController的UI时意外发现nil

ios - 如何修复表格 View 的搜索栏与状态栏重叠

swift - Firebase 数据库 - fatal error : Unexpectedly found nil while unwrapping an Optional value

swift - 用户是否可以搜索 map 以查看我在 swift 中固定的位置