我们正在尝试在选择时从UIPicker视图中删除数据,但是,它只删除第一个字符串"选择您的时间"选择UIPicker中的任何字符串。回去后,"选择你的时间"也重新加载。需要重新加载功能,否则我们的代码不会删除任何内容。
import Foundation
import UIKit
import Firebase
import FirebaseDatabase
class timeSinglesViewController:UIViewController,UIPickerViewDataSource,UIPickerViewDelegate {
@IBOutlet weak var myPicker: UIPickerView!
@IBOutlet weak var myLabel: UITextField!
var pickerData = ["Select You're Time","6:30", "7:30", "8:30", "9:30", "10:30", "11:30", "12:30", "1:30", "2:30", "3:30", "4:30", "5:30", "6:30", "7: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 row = Int()
let ref = FIRDatabase.database().referenceFromURL("deleted url")
ref.child("Time").setValue(myLabel.text)
pickerData.removeAtIndex(row)
myPicker.reloadAllComponents()
}
}
任何想法都表示赞赏。谢谢!