Uitableviewcell expression return error in Swift

Asked

Viewed 37 times

2

class OcorrenciaVinculadaCell: UITableViewCell{

    @IBOutlet weak var tipoOcorrencia: UITextField!
    @IBOutlet weak var descricao: UITextField!

}

class OcorrenciaVinculadasViewController: UITableViewController {

    var id:Int = 0;
    var schedulingId = 0;

    var ocorrencias:Array<Ocorrencia> = [];

    override func viewDidLoad() {
        self.schedulingId = Util.schedullingId;

        OcorrenciaHttp.GetOcorrencia(
            success: {
                (ocorrencias) in
                self.ocorrencias = ocorrencias;
                self.tableView.reloadData();
            }
            ,fail: { (error) in
                print("Failure: \(error.localizedDescription)");
            }
        );
    }

    @IBAction func createOcorrenciaButton(_ sender: Any) {
        Util.schedullingId = schedulingId;
    }

    override func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return ocorrencias.count
    }

    override func tableView(_ tableView: UITableView, cellForRowAt
    indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: "itemCell", for: indexPath) as! OcorrenciaViewCell

        let ocorrencia = ocorrencias[indexPath.row]

        cell.tipoOcorrencia.text = Util.GetText(text:ocorrencia.tipoOcorrencia?.Name) as? String;
        cell.descricao.text = Util.GetText(text: ocorrencia.descricao) as? String;

        return cell
    }

In return keeps giving the error:

Cannot convert return expression of type 'OcorrenciaViewCell' to return type 'UITableViewCell'
  • 1

    this is occurring because the function tableView waits for an object of the type to be returned UITableViewCell but you are returning cell which is an object of the type OcorrenciaViewCell: let cell = tableView.dequeueReusableCell(withIdentifier: "itemCell", for: indexPath) as! OcorrenciaViewCell. You’d have to convert cell in UITableViewCell only your question does not show the statement of OcorrenciaViewCell to know if it is possible or would have to create a conversion method.

1 answer

2


in the

 override func viewDidLoad() { ...

add:

self.tableview.register(OcorrenciaViewCell.self, forCellReuseIdentifier:"itemCell") 

Check in the cell if Voce put Identifier as "itemCell"

enjoying, always call the super in

override func viewDidLoad() { 
   super.viewDidLoad()
 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.