ios - 使用类方法实例化 UITableViewCell 会有内存管理问题吗?
问题描述
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()
}
}
通过使用这种方法实例化一个 tableView Cell。我们会面临任何与内存管理相关的问题吗?
解决方案
简而言之,没有。
当您向 tableview 注册单元类时,您不需要手动执行此操作,但是:
// 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
}
推荐阅读
- amazon-web-services - 在 DynamoDB 中聚合符合我们访问模式的数据
- image - 如何用值/文本替换 Gimp 中的粗线?
- java - Java:如何在特定时间后“打破”开关盒?
- java - 基于 IPv6 的 Android Things UDP 套接字
- bash - 检查变量是否包含特定的文本字符串 bash
- smooch - 如何在 Smooch 中阻止用户 - 垃圾邮件发送者
- r - 使用“滚动”组进行分组后总结
- soap - 使用类自定义来解决 java WSIMPORT 中的这种冲突
- java - 尝试创建错误检查方法,以便当计数器为 0 时计数器不会递减
- c# - 通过 MongoDB C# 驱动程序使用 SSL 连接到 DocumentDB