【问题标题】:Query on PFUser according to key value (Swift)根据键值查询PFUser(Swift)
【发布时间】:2015-10-06 22:16:56
【问题描述】:

我已将 PFUser 保存为此类中的指针。我想检索用户的名字和相应的“点值” 我在下面尝试将该数据附加到它的单元格值,但它只返回该键值的最后一个检索对象。

  var innerQuery : PFQuery = PFUser.query()!
  innerQuery.whereKeyExists("objectId")
  let query = PFQuery(className: "myClass")
  query.whereKey("userId", matchesQuery: innerQuery)
  query.whereKey("points", greaterThan: 1000)

        query.findObjectsInBackgroundWithBlock{ (objects: [AnyObject]?, error: NSError?) -> Void in

            if error == nil {
                if let objects = query.findObjects() as? [PFObject]{
                    for object in objects {

            if let listPoints = object.objectForKey("points") as? Int {


                            var temp = String(listPoints)
                            cell.pointStatus.text = temp

                        }

                    }
                }
            }

            else{
                println(error?.description)
            }


        }

我在单独的呼叫中检索用户的名字和个人资料图片。除了积分查询外,一切都正常。

    if let pfuser = userProfile["first_name"] as? String{
    if let pfimage = userProfile["profile_picture"] as? PFFile{ 

    pfimage.getDataInBackgroundWithBlock({
        (result, error) in

        cell.userIcon.image = UIImage(data: result!)
         cell.userName.text = username

    })

        }

    }

【问题讨论】:

    标签: ios swift parse-platform pfuser


    【解决方案1】:

    看来您只是将listPoints 的值写入一个单元格

    var temp = String(listPoints)
    cell.pointStatus.text = temp
    

    如果要显示多个点值,则需要更改单元格引用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多