美文网首页
UItableView、UITableViewCell常见扩展

UItableView、UITableViewCell常见扩展

作者: 白色天空729 | 来源:发表于2018-05-21 22:58 被阅读6次
//
//  CommonTableViewCell.swift
//  RZStop
//
//  Created by 郑东喜 on 2018/4/27.
//  Copyright © 2018年 Zzz. All rights reserved.
//


class CommonTableViewCell: UITableViewCell,RegisterCellFromNib {
    
    func setUI() -> Void {
        
    }
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: .default, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        
        /// 延长系统自带分割线
        self.preservesSuperviewLayoutMargins = false
        self.separatorInset = UIEdgeInsets.zero
        self.layoutMargins = .zero
        
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension UITableViewCell {
    func cell_addV(_ addV : UIView) {
        contentView.addSubview(addV)
    }
}


protocol RegisterCellFromNib {}

extension RegisterCellFromNib {
    
    static var identifier: String { return "\(self)" }
}

extension UITableView {
    
    func zdx_register(_ cellClass : AnyClass) {
        register(cellClass.self, forCellReuseIdentifier: "\(cellClass.self)")
    }
    
    /// 从缓存池池出队已经存在的 cell
    func zdx_dequeueReusableCell<T: UITableViewCell>(indexPath: IndexPath) -> T where T: RegisterCellFromNib {
        return dequeueReusableCell(withIdentifier: T.identifier, for: indexPath) as! T
    }
}

相关文章

网友评论

      本文标题:UItableView、UITableViewCell常见扩展

      本文链接:https://www.haomeiwen.com/subject/urrcjftx.html