ios swift 纯代码设置UITableViewCell的style

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样式属性!

猜你喜欢

转载自blog.csdn.net/baidu_40537062/article/details/123898185
今日推荐