Why UITableView cells can’t have a custom init?

Vaibhav Singh
1 min readNov 10, 2022

--

When it comes to custom tableView cells there are 2 ways to init them:

  1. awakeFromNib() — Init from a XIB file
  2. init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) — Init in code

We might think of adding another init with some dependencies to set up the cell’s view components but then we won’t be able to re-use the cell in the tableView. To be able to register a cell to be reused we have to use one of the default initializations, if we want to configure the cell, we will have to add a separate method to do that!

Even if we were able to add a custom init, we might run into some issues as the init for a cell is called only once and then it might be reused. So the custom setup we intended to do for the cell, will never happen when its reused!

--

--

Vaibhav Singh
Vaibhav Singh

Written by Vaibhav Singh

iOS Engineer @ Pulselive Leading development of the Premier League App!

No responses yet