我有一个自定义单元格的TableView需要相当长的配置,并在我的应用程序中多次使用。我想避免重复的代码,并在一个地方配置单元格。我可以创建一个这样的功能吗?在TableView之外配置自定义TableViewCell?
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "betterPostCell", for: indexPath) as! BetterPostCell
return configureCell(cell)
}
理想情况下,我就可以把configureCell
我BetterPostCell类。这可能吗?
里面的你'BetterPostCell' class add'configure(withItem item:T)'你可以调用cell.configure(withItem:_item)并返回单元格 –
Lamar