1、协议
//
// ReusableCell.swift
// reusecell
//
// Created by targetcloud on 2017/3/26.
// Copyright © 2017年 targetcloud. All rights reserved.
//
import UIKit
protocol ReusableCell : class{
static var reuseableIdentifier :String {get}
static var nib : UINib? {get}
}
extension ReusableCell where Self : UITableViewCell{
static var reuseableIdentifier :String{
//return "\(self)"
//两种实现方式都可以
print(" --- \(self) \(String(describing: self)) --- ")
return String(describing: self)
}
static var nib : UINib? {
return nil
}
}
extension UITableView{
func registerCell<T : UITableViewCell >(_ cell : T.Type) where T : ReusableCell{
if let nib = T.nib{
register(nib, forCellReuseIdentifier: T.reuseableIdentifier)
}else{
register(cell, forCellReuseIdentifier: T.reuseableIdentifier)
}
}
func dequeReusableCell<T : UITableViewCell>(indexPath : IndexPath) -> T where T : ReusableCell{
return dequeueReusableCell(withIdentifier: T.reuseableIdentifier, for: indexPath) as! T
}
}
//
// TGNib2Cell.swift
// reusecell
//
// Created by targetcloud on 2017/3/26.
// Copyright © 2017年 targetcloud. All rights reserved.
//
import UIKit
class TGNib2Cell: UITableViewCe