Differences between tableView.dequeueReusableCell and Uitableviewcell

Asked

Viewed 233 times

3

Good night,

I would like to know what is the difference between the parameters below, if one is but effective than the other, less chances of error etc. From what I see in practice both do the same thing. Ever since I thank.

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") 
}

1 answer

6


TheReusableCell reuses resources that are not used. That is, if you have already prompted 20 cells, but you are only showing 19, it will take the 1 that is not being used to instantiate the new cell you need.

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

  • Thanks Andreza, for the clarification I had no idea.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.