Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys, I'm making an app with a tableview controller that I use the latest version of xcode the 9.2, and development in swift 4, then the fact is that the cells are seen in this way .
I would like to get this result: this


Swift
import UIKit

class CantieriViewController: UITableViewController {
    
    override func viewDidLoad()
    {
        super.viewDidLoad()
        
        
        self.view.backgroundColor = UIColor.white
        tableView.register(MyCell.self, forCellReuseIdentifier: "cellId")
        
    }
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) ->Int
    {
        return 5
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) ->UITableViewCell
    {
        return tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath as IndexPath)
    }
    
}

class MyCell: UITableViewCell {
    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupViews()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    let nameLabel: UILabel = {
        let label = UILabel()
        label.text = "Sample Item"
        label.translatesAutoresizingMaskIntoConstraints = false
        label.font = UIFont.boldSystemFont(ofSize: 14)
        return label
    }()
    
    func setupViews() {
        addSubview(nameLabel)
        addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": nameLabel]))
        addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": nameLabel]))
    }
}


What I have tried:

I do not know how to solve it
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900