简体   繁体   中英

UITableView with CustomCell not show data Swift4 on Xcode9

I read the other topics, but not solves my problem, I create a tableview and your cells with same value to make tests, but when I execute my project nothing data is showed. I put 5 size of rows to only to test. I don't know why my code not works.

My storyboard: 在此处输入图片说明

TableViewCellVenda.swift

class TableViewCellVenda: UITableViewCell {

    @IBOutlet weak var cellView: UIView!
    @IBOutlet weak var imageCloud: UIImageView!
    @IBOutlet weak var labelValorTotal: UILabel!
    @IBOutlet weak var labelQtdItens: UILabel!
    @IBOutlet weak var labelCliente: UILabel!
    @IBOutlet weak var labelDataVenda: UILabel!

    override func awakeFromNib() {
        super.awakeFromNib()

    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}

ViewControllerVendas.swift

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    // UI View
    @IBOutlet weak var tableViewVendas: UITableView!
    @IBOutlet weak var waitView: UIActivityIndicatorView!

    // DB
    var db: OpaquePointer?
    var count : Int = 0

    // Data
    var saleOrders : [SaleOrder] = []

    override func viewDidLoad() {
        super.viewDidLoad()


        self.waitView.startAnimating()
        self.waitView.hidesWhenStopped = true

        tableViewVendas.delegate = self
        tableViewVendas.dataSource = self


    }

    // TableView
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 5
    }

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cellVenda") as! TableViewCellVenda
        print("Cell for row")
        cell.labelCliente.text = "Nome do Cliente"
        cell.labelDataVenda.text = "14/02/1991"
        cell.labelQtdItens.text = "20"
        cell.labelValorTotal.text = "R$ 542,22"

        return cell
    }

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


}

Emulator: 在此处输入图片说明

Try adding a new swift UIKit file with a class of type UITableView and do all the tableview setup in there. And of coarse set the tables's class as this UITableView class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM