我正在为静态表视图构建一个库,它工作正常,但我遇到了通用闭包的问题.
到目前为止看起来像这样:
orderForm = Form(tableView: orderTable) { f in f.section { s in s.footer("Při platbě nejsou účtovány žádné další poplatky.") s.cell("Selection") .configure { (cell,path) in let c = cell as! ProfileSelectionCell c.titleLabel?.text = "Způsob platby" c.detailLabel?.text = self.paymentType.first } s.cell("Selection") .configure { (cell,path) in let c = cell as! ProfileSelectionCell c.titleLabel?.text = "Balíček" c.detailLabel?.text = "20 kr. za 1000 Kc" }.selected { path in } } }
我想将“cell”变量转换为适当的类型,在本例中为ProfileSelectionCell.
以下是单元类的来源:
class Cell { internal let id: String internal var configure: ((cell: UITableViewCell,path: NSIndexPath) -> Void)? internal var selected: ((path: NSIndexPath) -> Void)? init(id: String) { self.id = id } func configure(config: ((cell: UITableViewCell,path: NSIndexPath) -> Void)?) -> Self { self.configure = config return self } func selected(selected: (path: NSIndexPath) -> Void) -> Self { self.selected = selected return self }}
我的问题是,如果我使配置方法通用,不可能将配置闭包存储到单元格变量,如果我使整个单元格通用,我不能将单元格保存到节类中的数组,依此类推..
这可以解决吗?