Swift自定义TableVIewCell 和OC 自定义TableVIewCell 的区别

oc 

cell里
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) { [self addSubview];//添加控件 } return self; } 调用 static NSString *talkID=@"talkID"; CSDA_LZSearchTalkTVCell *cell=[tableView dequeueReusableCellWithIdentifier:talkID]; if (cell==nil) { cell=[[CSDA_LZSearchTalkTVCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:talkID]; } cell.selectionStyle=UITableViewCellSelectionStyleNone; return cell;

Swift 

cell 里
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
       
        self.setUI()//添加控件
        
    }
调用
 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let reuSre = "cell"
        let cell = MasonryTableViewCell(style:UITableViewCellStyle.default,reuseIdentifier:reuSre)
        cell.selectionStyle=UITableViewCellSelectionStyle.none
        cell.titeLB.text = array[indexPath.row] as? String
        let imageName = String (indexPath.row)
        cell.imageVI.image = UIImage(named:imageName)
        return cell
    }
原文地址:https://www.cnblogs.com/Lrx-lizi/p/7268778.html