1.dequeueReusableCell(withIdentifier:)方法需要注册

 func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell:UITableViewCell!

        if let cell1 = tableView.dequeueReusableCell(withIdentifier: "cell"){
            cell = cell1
        }else{
            cell = UITableViewCell(style: .subtitle, reuseIdentifier: "cell")

        }


        cell.textLabel?.text = String(indexPath.row)
        return cell
     
    }

2.dequeueReusableCell(withIdentifier:for:)需要注册返回的的是default类型cell,如果想返回其他类型cell,只能用第一个方法

extension UITableViewCell {

    
    public enum CellStyle : Int {

        
        case `default` = 0

        case value1 = 1

        case value2 = 2

        case subtitle = 3
    }

3.我的另外一篇博客

iOS swift cell创建的两种方式注册与不注册

其他相关博客
swift中如何正确设置UITableViewCell的UITableViewCellStyle样式属性!

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注