Reputation: 187
extension SettingsTableViewController {
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = SettingsTableViewCell.getSettingTableViewCell(tableview: tableView, indexPath: indexPath)
return cell
}
}
class SettingsTableViewCell: UITableViewCell {
static let identifier = "SettingsTableViewCell"
public class func getSettingTableViewCell(tableview: UITableView, indexPath: IndexPath) -> SettingsTableViewCell {
if let cell = tableview.dequeueReusableCell(withIdentifier: self.identifier, for: indexPath) as? SettingsTableViewCell {
return cell
}
return SettingsTableViewCell()
}
}
By instantiating a tableView Cell with this approach. Are we going to face any memory management related issue?
Upvotes: 0
Views: 33
Reputation: 17874
In short, no.
You don't need to do that manually when you register your cell class with the tableview, however:
// e.g. in viewDidLoad
tableView.register(SettingsTableViewCell.self, forCellReuseIdentifier: "cell")
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! SettingsTableViewCell
return cell
}
Upvotes: 2