Как мне продолжить добавление нескольких прототипов клеток - PullRequest
0 голосов
/ 04 июля 2018

Я пытаюсь добавить две прототипные ячейки в свой 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
    }

    }

Изображение раскадровки

1 Ответ

0 голосов
/ 04 июля 2018

Вам нужно настроить свою модель так, чтобы она отвечала внутри 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
     }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...