我试图从Parse获取数据并将其显示为UILabel,但我没有得到任何结果

时间:2015-05-21 03:42:14

标签: ios xcode swift parse-platform

当我运行此代码时,它不会将alertLabel更新为我在解析时设置的消息。我没有收到任何错误,标签正确链接到我的ViewController类。

我对编码非常陌生,所以我很感谢你的帮助。提前谢谢。

class ViewController: UIViewController {

    @IBOutlet weak var alertLabel: UILabel!

    var output : PFObject!
    let theObjectID = "M0qEFWMxYI"
    let theClass = "bobcatStatus"


    override func viewDidLoad() {
    super.viewDidLoad()

    }

    func displayData() {
        var thisQuery = PFQuery(className: theClass)
        thisQuery.getObjectWithId(theObjectID)

        if let alertOutput = output["alertMessage"] as? String {
        alertLabel.text = alertOutput
        }

        else {
            alertLabel.text = "Error loading data."
        }
    }

        // Do any additional setup after loading the view, typically from a nib.

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

Xcode 6.2.3

1 个答案:

答案 0 :(得分:0)

@brianprsly我假设您正在尝试使用对象ID从解析类获取记录,尝试在您的项目中实现以下代码。如果它对你有帮助,请告诉我。

参考:https://www.parse.com/docs/ios/guide#objects-retrieving-objects

var query = PFQuery(className: theClass)
query.getObjectInBackgroundWithId(theObjectID) {
   (theClassObj: PFObject?, error: NSError?) -> Void in
   if error == nil && theClassObj != nil {
      println(theClassObj)
      if let alertOutput = theClassObj["alertMessage"] as? String {
         alertLabel.text = alertOutput
      }else {
         alertLabel.text = "Error loading data."
      }
   } else {
      println(error)
   }
}