How to update UITableView with two-dimensional array?

0

I can not update my 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 ideas how to do this?

    
asked by anonymous 30.09.2015 / 19:17

1 answer

0

Having a array of dictionaries , as 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
}
    
01.10.2015 / 13:40