保存滑块值 [英] Saving slider value
问题描述
我正在尝试保存滑块值并将其保存到 Firebase 数据库.我已经解决了以前的问题(感谢 Stack Overflow!),现在正在将字符串"上传到数据库,但我想获取滑块的值.我显然错过了一些东西,只是不知道是什么.我一直在这方面工作很长时间,所以寻找其他人的观点.我为凌乱的代码道歉.这就是你对新手的体验 ;-) 代码如下.感谢您的任何想法.
I am trying to save a slider value and save it to Firebase Database. I have progressed from previous problems (Thanks Stack Overflow!) and now am uploading 'String' to the database but I want to get the value of the slider instead. I'm missing something obviously, just don't know what. I've been working on this so long so looking for someone else's perspective. I apologize for the messy code. That's what you get with newbies ;-) The code is below. Thanks for any thoughts.
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)
}
}
推荐答案
我已经开始工作了,代码如下.感谢您查看此内容,并希望对其他人有所帮助.
I've got this working and the code is below. Thanks for checking this out and hope it helps others.
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)
}
}
这篇关于保存滑块值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!