我有一個自定義單元格的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