gpt4 book ai didi

ios - 解析查询不显示最新数据

转载 作者:行者123 更新时间:2023-11-30 13:56:03 25 4
gpt4 key购买 nike

import UIKit
import Parse

class loadMainViewController: UIViewController {

//create new pfQuery - This is the bridge between our app and Parse: "trivia" is our class name on Parse
let queryTrivia: PFQuery = PFQuery(className:"trivia")

@IBOutlet weak var label1: UILabel!

override func viewDidLoad() {
super.viewDidLoad()
//retrieve data from parse query
retrieveTrivia()
}

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

func retrieveTrivia() {

//This CLOSURE gives access to all objects in "trivia" class using our queryTrivia Bridge
queryTrivia.findObjectsInBackgroundWithBlock { (objects:[PFObject]?, error:NSError?) -> Void in
if( error == nil ){

print("error is nil")
}
var didLoad = true

// Loop through the objects array
for triviaObject in objects!{

// Retrieve data for each object (key, question, ans2, ans3, correctAns)
let triviaQuest : String? = (triviaObject as PFObject)["question"] as? String
let triviaAns2 : String? = (triviaObject as PFObject)["ans2"] as? String
let triviaAns3 : String? = (triviaObject as PFObject)["ans3"] as? String
let triviaAns : String? = (triviaObject as PFObject)["correctAns"] as? String
let triviaKey : Int? = (triviaObject as PFObject)["key"] as? Int

//Check that items are not nil, and create trivia object, add to triviaQuestions Array
if ( triviaKey != nil && triviaQuest != nil && triviaAns2 != nil && triviaAns3 != nil && triviaAns != nil){
let trivia = triviaQuestion(Key: triviaKey!, Question: triviaQuest!, Answer: triviaAns!, WrongAnswer: triviaAns2!, WrongAnswer2: triviaAns3!)
triviaQuestions.append(trivia) // append to the global array of trivia questions

}else{
self.label1.text = "Network Error"
didLoad = false
}
}

for element in triviaQuestions{
print(element.Key)
}

if (didLoad == true) {
//perform segue to View Controller : Main menu
self.performSegueWithIdentifier("finnishLoad", sender: self)
}
}
}
}

我的问题在于当我在retrieveTrivia()方法中查询数据时。这些查询似乎可以解决一些问题。保存到 TriviaQuestion、TriviaAns、TriviaAns2、TriviaAns3 中的数据是旧数据,此后我使用解析网站更改了这些数据,只需单击单元格并手动编辑每个字段即可。此外,我似乎无法获取关键字段,并且它总是返回为零。

当我运行这个时,triviaAns 变量包含“Cow”,但是,在线查看数据时它显示“Mozzarella”。

知道为什么我在更新字段后会收到错误的数据以及为什么关键字段返回为零吗?

这是数据现在的样子 enter image description here

最佳答案

确保您连接到正确的 Parse 应用 - 检查应用委托(delegate)中对 setApplicationId:clientKey 的调用中的键是否与 Parse.com 上应用设置中显示的键匹配

关于ios - 解析查询不显示最新数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33600683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com