How to update Uitableview with two-dimensional array?

Asked

Viewed 81 times

0

I’m not getting my upgrade UITableView with the data contained in Array:

var linha: NSArray = [["Categoria": "Desenvolvimento para IOS", "Imagem": "swift.png"],["Categoria": "Programação orientada a objeto", "Imagem": "php.png"]]

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

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! HomeViewCell

    cell.titulo.text = //
    cell.imagem.image = //

    return cell
}

Any idea how to do that?

1 answer

0

Having a array of Dicties, as is the case that you exemplified, just do something like this:

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return count(linha)
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! HomeViewCell

    let registro = linha[indexPath.row]

    cell.titulo.text = registro["Categoria"]
    cell.imagem.image = registro["Imagem"]

    return cell
}

Browser other questions tagged

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