swift 代码自定义cell

   func setupTableVie()   {
        
        
        tableView = UITableView(frame:  CGRect(x: 0 , y: 64, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height ), style: UITableViewStyle.plain)
        tableView?.dataSource = self
        tableView?.delegate = self
        self.view.addSubview(tableView!)
//        self.tableView?.register(TasksCell().classForCoder, forCellReuseIdentifier: "cell")
//        self.tableView?.register(UINib.init(nibName: "TasksCell", bundle: nil), forCellReuseIdentifier: "cell")
        view.backgroundColor = UIColor.globalBackgroundColor()
        automaticallyAdjustsScrollViewInsets = false
        
        
    }

  func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    //每一块有多少行
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return  array.count
    }
    

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
//        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
        
        let identifier = "mainCell"
        let cell = TasksCell(style: UITableViewCellStyle.subtitle, reuseIdentifier: identifier)
//        cell.textLabel!.text = array[indexPath.row].name
//         cell.detailTextLabel!.text = array[indexPath.row].name
        
        return cell

    }
    
    

    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 160;
    }
    


import Foundation
import UIKit

class TasksCell: UITableViewCell {
    

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
   
    
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {// 代码创建
        super.init(style: style, reuseIdentifier: reuseIdentifier)
   
        setupUI()

    }
    
    
}
 
 


你可能感兴趣的:(swift 代码自定义cell)