【发布时间】:2017-08-30 23:26:38
【问题描述】:
我有一个带有自定义单元格的 TableView,它需要相当长的配置并且在我的应用程序中多次使用。我想避免重复的代码,只在一个地方配置单元格。我可以创建这样的函数吗?
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "betterPostCell", for: indexPath) as! BetterPostCell
return configureCell(cell)
}
理想情况下,我可以将configureCell 放入我的 BetterPostCell 类中。这可能吗?
【问题讨论】:
-
在
BetterPostCell类中添加configure<T>(withItem item:T)您将调用 cell.configure(withItem: _item) 并返回单元格
标签: ios swift uitableview