Differences between tableView.dequeueReusableCell and UITableViewCell

0

Good evening,

I would like to know what is the difference between the parameters below, if one is more effective than the other, less chance of error etc. What I see in practice both do the same thing. Thanks in advance.

1)

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

   let cell = tableView.dequeueReusableCell(withIdentifier:"cellName”, for: indexPath) 
}

2)

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell = UITableViewCell(style: UITableViewCellStyle.default, reuseIdentifier: "cellName") 
}
    
asked by anonymous 08.04.2017 / 00:42

1 answer

2

DequeueReusableCell reuses resources that are not used. That is, if you have already instantiated 20 cells, but it is only showing 19, it will get the 1 that is not being used to instantiate the new cell it needs.

Already with the other method you are always instantiating a new cell. The documentation recommends dequeueReusableCell.

    
13.04.2017 / 21:21