Parse.com for Xcode to make simple app like trivia crack type

拟墨画扇 提交于 2020-01-06 15:06:48

问题


//
//  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) {
    }
}

That's my entire code. My Parse.com is organized as objectId, createdAt, updatedAt, ACL, Questions (string), Answers (array of strings), Answer (string but its value is a number.)

https://www.youtube.com/watch?v=3Yeicy7wCBA this is the youtube video that I'm following directly.

I know I'm definitely missing something, otherwise it would work, but I'm just having a shitty time debugging it.


回答1:


I had the same problem. Spent a half a day on this one. I made two changes.

  1. Check on Parse and make sure that your Answer column is named "Answer". Mine was named "Array", and that was screwing me up.

  2. I tinkered with the optionals and their exclamation points and question marks. See the code below.

        (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



来源:https://stackoverflow.com/questions/30182556/parse-com-for-xcode-to-make-simple-app-like-trivia-crack-type

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!