我正在尝试获取拥有 Vitrine 的客户的姓名。
这是我的代码。
为了保存我正在这样做的数据:
self.vitrine["username"] = PFUser.currentUser()?.username
self.vitrine["name"] = nameTextField.text as String
var relation = self.vitrine.relationForKey("client")
relation.addObject(self.client)
self.vitrine.saveEventually { (success, error) -> Void in
if(error == nil){
}else{
println(error?.userInfo)
}
self.fetchAllVitrines()
self.navigationController?.popToRootViewControllerAnimated(true)
}
}
它有效。在 Parse 中,我可以看到关系有效。
我正在尝试访问这样做的关系数据:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("vitrineCell", forIndexPath: indexPath) as! VitrineTableViewCell
var object: PFObject = self.vitrineObjects.objectAtIndex(indexPath.row) as! PFObject
cell.nomeLabel.text = object["name"] as? String
let x: PFRelation = object["client"] as! PFRelation
// cell.clientNameTextView.text = object["client"]["name"] as String
return cell
}
但是当我在客户端列中记录数据时,对我来说出现的是:
<PFRelation: 0x7b7f1390, 0x7b7cfdc0.client -> Client>
请有人帮助我。我坚持了2天。我阅读了 Parse Doc 的 3 次以上。我找不到办法做到这一点。
问候, 迪奥戈·阿马拉尔
好吧,我添加代码:
query!.getFirstObjectInBackgroundWithBlock {
(object: PFObject?, error: NSError?) -> Void in
if error != nil || object == nil {
println("The getFirstObject request failed.")
} else {
println(object)
cell.clientNameTextView.text = object["name"] as? String
}
}
但是这条线:cell.clientNameTextView.text = object["name"] as? String
给我一个错误。“无法分配“字符串”类型的值?到“字符串!”类型的值”...
我已经尝试过:
cell.clientNameTextView.text = object["name"] as! String
cell.clientNameTextView.text = object["name"] as String
cell.clientNameTextView.text = object["name"] as? String
我该如何解决?