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

原文地址:https://blog.csdn.net/baidu_40537062/article/details/123898185

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_38992.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

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