0
我正在創建一個預訂應用程序。我正在使用UIPickers顯示打開的時間。我有選擇器功能齊全,但不知道如何在用戶從提供的選項中選擇一個後刪除預訂時間。我對Xcode比較陌生,所以任何信息都非常感謝!從選擇中刪除字符串從UIPicker
import Foundation
import UIKit
import Firebase
import FirebaseDatabase
class sTimeSelectionViewController:UIViewController,UIPickerViewDataSource,UIPickerViewDelegate {
@IBOutlet weak var myPicker: UIPickerView!
@IBOutlet weak var myLabel: UILabel!
let pickerData = ["9:30","10:30","11:30","12:30","1:30","2:30"]
override func viewDidLoad() {
super.viewDidLoad()
myPicker.dataSource = self
myPicker.delegate = self
myPicker.tag = 1
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerData.count
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return pickerData[row]
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
myLabel.text = pickerData[row]
}
@IBAction func postData(sender: AnyObject) {
let ref = FIRDatabase.database().referenceFromURL("deleted URL")
ref.child("Time").setValue(myLabel.text)
}
}
謝謝!
嗨,獅子座。感謝您的代碼!我有一個問題。我已經將您的代碼添加到我的項目中,並且在按下按鈕選擇該行之前數據正在刪除自己(當您滾動數據時,數據會自動刪除)。任何想法如何可以修復? –