0
我一直在試圖打印PFQuery
叫我viewWillAppear
的細胞,但我從該行得到的錯誤:斯威夫特 - 「PFObject是無法轉換爲NSString的」
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)
}
}
好的,所以「消息」是一個PFObject。你不想分配這個對象,但它只有一個領域,不是嗎? – freytag
如果您想在控制檯中查看消息內容,則可以執行「println(message)」作爲調試。 @freytag可能會讓你指向正確的方向。 – Mattias