我正在创建一个预订应用。我正在使用UIPickers来显示开放时间。我有拣货员功能齐全但不确定如何在用户从提供的选项中选择一个后删除预订时间。我对Xcode比较新,所以非常感谢任何信息!!
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)
}
}
谢谢!
答案 0 :(得分:2)
首先将pickerData声明从常量更改为变量
var pickerData = ["9:30","10:30","11:30","12:30","1:30","2:30"].
接下来,您需要在myLabel.text代码之后删除方法didSelectRow中的数组元素
pickerData.removeAtIndex(row)
并重新加载您的选择器
myPicker.reloadAllComponents()