Sobes.tech
Junior — Middle

Como é feita a configuração das células no sistema?

sobes.tech IA

Resposta da IA

No iOS, a configuração das células (UITableViewCell ou UICollectionViewCell) geralmente ocorre nos métodos do delegado da tabela ou coleção, como tableView(_:cellForRowAt:) ou collectionView(_:cellForItemAt:).

Principais passos:

  1. Registar a célula:

    • Através de código usando register(_:forCellReuseIdentifier:).
    • Ou através de storyboard/xib.
  2. Obter a célula do pool de reutilização:

    let cell = tableView.dequeueReusableCell(withIdentifier: "CellIdentifier", for: indexPath)
    
  3. Configurar o conteúdo da célula:

    • Preencher etiquetas de texto, imagens e outros elementos da interface.
    • Pode criar subclasses personalizadas de células para lógica mais complexa.

Exemplo de configuração de célula no UITableView:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath)
    cell.textLabel?.text = "Linha \(indexPath.row)"
    return cell
}

Assim, a configuração das células é o processo de obter uma célula reutilizável e preenchê-la com dados para exibição.