Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //存两个字典, 一个是identifier - cell
- //一个是 identifier - cell type
- var dic = [String: UITableViewCell.Type]() // identifier : cell
- dic["cell"] = UITableViewCell.self
- var cells = [String : [UITableViewCell]]()
- cells["cell"] = [UITableViewCell]()
- extension UITableView{
- func dequeueMyReusableCell(with Identifier: String) -> UITableViewCell{
- if let list = cells[Identifier], list.count > 0 {
- var l = list
- let cell = l.removeFirst()
- cell.prepareForReuse()
- cells[Identifier] = l
- return cell
- }else{
- if let type = dic[Identifier] {
- return type.init()
- }else{
- return UITableViewCell()
- }
- }
- }
- }
- var tableView = UITableView()
- let cell = tableView.dequeueMyReusableCell(with: "cell")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement