保存滑块值

时间:2017-04-30 00:42:56

标签: database firebase save uislider

我正在尝试保存滑块值并将其保存到Firebase数据库。我已经从以前的问题(感谢Stack Overflow!)进展,现在正在将'String'上传到数据库,但我希望得到滑块的值。我显然缺少一些东西,只是不知道是什么。我一直在研究这个问题,所以寻找别人的观点。我为凌乱的代码道歉。这就是你得到的新手;-)代码如下。谢谢你的任何想法。

import UIKit
import FBSDKCoreKit
import FBSDKLoginKit
import FirebaseDatabase
import FirebaseStorage


class SecondViewController: UIViewController {

var myEmail: String?

var ref:FIRDatabaseReference?
var currentValue = String.self


@IBOutlet var emailShown: UIView!

@IBOutlet weak var myEmailDisplayed: UILabel!


@IBOutlet weak var sliderLabel: UILabel!


@IBOutlet weak var verticalSlider: UISlider!

       {
            didSet{
                verticalSlider.transform = CGAffineTransform(rotationAngle: CGFloat(-M_PI_2))

            }
    }

let img:UIImageView = UIImageView(frame: CGRect(x: 30, y: 180, width: 250, height: 320))

@IBAction func verticalSliderChanged(_ sender: UISlider) {

        let currentValue = String(sender.value);

        sliderLabel.text = "\(currentValue)"

}


@IBAction func checkmarkButtonPressed(_ sender: AnyObject!) {

    //Count number of download URLs in child 'Books'



    //Use 'Post' to save currentValue variable to database by book and email

    self.ref = FIRDatabase.database().reference()

    let currentValue = String(describing: self.currentValue)

    self.ref?.child(uuid).child("Slider Value").setValue(currentValue)

    }

}

1 个答案:

答案 0 :(得分:0)

我已经开始工作,代码如下。感谢您查看此内容并希望它可以帮助其他人。

 class SecondViewController: UIViewController {

    var myEmail: String?
    var myName: String?
    var myGender: String?
    var myLocation: String?
    var myEducation: String?
    var myRelationshipStatus: String?

    var ref:FIRDatabaseReference?
    var currentValue = String.self
    var bookRating: FIRDatabaseReference!

@IBOutlet weak var emailDisplayed: UILabel!
@IBOutlet weak var sliderLabel: UILabel!
@IBOutlet weak var verticalSlider: UISlider!


       {
            didSet{
                verticalSlider.transform = CGAffineTransform(rotationAngle: CGFloat(-M_PI_2))

            }
    }

let img:UIImageView = UIImageView(frame: CGRect(x: 30, y: 180, width: 250, height: 320))

@IBAction func verticalSliderChanged(_ sender: UISlider) {

        let currentValue = String(sender.value);

        sliderLabel.text = "\(currentValue)"

}


@IBAction func checkmarkButtonPressed(_ sender: AnyObject!) {

    //Count number of download URLs in child 'Books'



    //Use 'Post' to save currentValue variable to database by book and email

    //self.ref = FIRDatabase.database().reference()

    //let currentValue = String(describing: self.currentValue)

    //self.ref?.child(uuid).child("Slider Value").setValue(currentValue)

    bookRating = FIRDatabase.database().reference().child("ratings").child("hjayanthi@gmail.com")
    addRating()

    }

func addRating() {

    let key = bookRating.childByAutoId().key
    let rating = ["id":key, "ratingValue": sliderLabel.text! as String]
    bookRating.child(key).setValue(rating)


}



}