[英]Swift - 'PFObject is not convertible to NSString'
我一直在尝试打印在单元格中的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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.