//
// ViewController.swift
// AP Attack
//
// Created by ddfulton on 5/8/15.
// Copyright (c) 2015 ddfulton. All rights reserved.
//
import UIKit
import Parse
class ViewController: UIViewController {
var Question: String!
var Answers: [String]!
var Answer: String!
@IBOutlet weak var QuestionLabel: UILabel!
@IBOutlet weak var Button1: UIButton!
@IBOutlet weak var Button2: UIButton!
@IBOutlet weak var Button3: UIButton!
@IBOutlet weak var Button4: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
CallData()
}
func CallData(){
var query : PFQuery = PFQuery(className: "QuestionsandAnswers")
query.getObjectInBackgroundWithId("Mo4HYEB8EC"){
(ObjectHolder : PFObject!, error : NSError!) -> Void in
if (error == nil){
self.Question = ObjectHolder["Question"] as String!
self.Answers = ObjectHolder["Answers"] as Array!
self.Answer = ObjectHolder["Answer"] as String!
if (self.Answers.count > 0){
self.QuestionLabel.text = self.Question
self.Button1.setTitle(self.Answers[0], forState : UIControlState.Normal)
self.Button2.setTitle(self.Answers[1], forState : UIControlState.Normal)
self.Button3.setTitle(self.Answers[2], forState : UIControlState.Normal)
self.Button4.setTitle(self.Answers[3], forState : UIControlState.Normal)
}
}
else{
NSLog("Error. Wrong!")
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func Button1Action(sender: AnyObject) {
}
@IBAction func Button2Action(sender: AnyObject) {
}
@IBAction func Button3Action(sender: AnyObject) {
}
@IBAction func Button4Action(sender: AnyObject) {
}
}
那是我的整个代码。我的Parse.com被组织为objectId,createdAt,updatedAt,ACL,Questions(字符串),Answers(字符串数组),Answer(字符串但其值是数字。)
https://www.youtube.com/watch?v=3Yeicy7wCBA这是我直接关注的YouTube视频。
我知道我肯定错过了一些东西,否则它会起作用,但我只是在调试它的时候很糟糕。
答案 0 :(得分:0)
我遇到了同样的问题。在这个上花了半天时间。我做了两处修改。
检查解析并确保您的答案列已命名为"答案"。我被命名为#34;阵列",这让我搞砸了。
我修改了选项及其感叹号和问号。请参阅下面的代码。
insert
if(error == nil){ self.Question = ObjectHolder?[" Question"] as!串 self.Answers = ObjectHolder?["答案"]为!排列 self.Answer = ObjectHolder?["答案"]为!串