Swift - ' PFObject不能转换为NSString'

时间:2015-07-21 02:52:50

标签: ios swift uitableview parse-platform

我一直在尝试在单元格中打印PFQuery中的viewWillAppear,但我从这一行得到错误:

cell?.textLabel?.text = message as NSString as String

这里是tableView cellForRowAtIndexPath的代码:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cellId: NSString = "cell"
    var cell: UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(cellId as String) as? UITableViewCell
    if (cell == nil) {
        cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: cellId as String)
    }
    let message = myMessagesArray![indexPath.row] as! PFObject
    cell?.textLabel?.text = message as NSString as String
    return cell!
}

这里是PFQuery

 var query = PFUser.query()
    query!.orderByAscending("Messages")
    query!.findObjectsInBackgroundWithBlock {
        (objects: [AnyObject]?, error: NSError?) -> Void in
        if error == nil {
            println("Successfully retrieved \(objects!.count) messages.")
            self.myMessagesArray = objects
            self.tableView?.reloadData()
        } else {
            println(error!.localizedDescription)
        }
    }

1 个答案:

答案 0 :(得分:0)

使用此代码:

let message = myMessagesArray[indexPath!.row] as! PFObject
cell.textLabel?.text = message.objectForKey("Messages") as? String