// 注册写法
public class func reuseCellWith(tableView:UITableView, indexPath:IndexPath) -> NewsListCell {
// 注册写法
let cell = tableView.dequeueReusableCell(withIdentifier: NSStringFromClass(self.self), for:indexPath) as! NewsListCell
return cell
}
// 非注册写法
public class func reuseCellWith(tableView:UITableView) -> NewsListCell {
// 非注册写法
guard let cell = tableView.dequeueReusableCell(withIdentifier: NSStringFromClass(self.self)), let checkCell = (cell as? NewsListCell) else {
return NewsListCell(style: .default, reuseIdentifier: NSStringFromClass(self.self))
}
return checkCell
}
初步验证后,发现内存占用差不多。所以建议使用第一种,代码量更少,只不过需要为tableview注册cell而已。
网友评论