Search code examples
iosswiftpfobject

How to get String from PFObject and display it into tableView cell?


func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier:"addCategoryCell")

    var user = self.searchResult[indexPath.row] as? [PFObject]
     println(user)
    cell.textLabel?.text = user["Article_Number"] as? String // error here
    return cell
}

I want to print the article number on the table row. I have tried this code but it's not working. In addition, the term searchResult contains objects array of array.


Solution

  • Update your code this way:

    var user = self.searchResult[indexPath.row] as! PFObject
    println(user)
    cell.textLabel?.text = user.objectForKey("Article_Number") as! String
    return cell