我一直在尝试在单元格中打印在我的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)
        }
    }

最佳答案

使用此代码:

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

关于ios - Swift-'PFObject无法转换为NSString',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31529586/

10-13 08:37