如何继续添加多个原型单元

时间:2018-07-04 17:55:41

标签: ios swift xcode uitableview

我正在尝试在UITableView上添加两个原型单元。但是,我不知道如何验证能够“返回”每个原型的正确单元。你们可以帮我吗?

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

        if ??? {

        let cell = itensTableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath) as! tableviewCell
            cell.nameCell.text = "Oculos"
            return cell
    }else{
        let cellAdicionar = itensTableView.dequeueReusableCell(withIdentifier: "cellIdAdc", for: indexPath) as! tableviewBotaoAdicionar
            cellAdicionar.botaoAdicionar.text = "Adicionar"

        return cellAdicionar
    }

    }

Storyboard Picture

1 个答案:

答案 0 :(得分:0)

您需要设置模型以在cellForRowAt内回答该问题

var arr = ["first","second","first"]

//

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

    let item = arr[indexPath.row]

    if item == "first" {
        let cell = itensTableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath) as! tableviewCell
        cell.nameCell.text = "Oculos"
        return cell
     } else {
        let cellAdicionar = itensTableView.dequeueReusableCell(withIdentifier: "cellIdAdc", for: indexPath) as! tableviewBotaoAdicionar
        cellAdicionar.botaoAdicionar.text = "Adicionar"
        return cellAdicionar
     }
}