gpt4 book ai didi

ios - swift - 'PFObject is not convertible to NSString'

转载 作者:行者123 更新时间:2023-11-30 14:13:04 27 4
gpt4 key购买 nike

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

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 is not convertible to NSString',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31529586/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com