Я не могу загрузить данные из базы данных для отображения результатов UIPickerView
.Я тестирую по значению массива исправлений UIPicker
могу загрузить данные в pickerView
, но когда я использую массив загрузки, json UIPickerViewDataSource
не может загрузить в окне выбора
может загрузить
var team = ["Apple", "Banana", "Tomato", "Corn", "Bean", "Orange", "Mango", "Mangoteen"]
Canot Load
var team: [AnyObject] = []
import UIKit
class getAllTeamViewController: UIViewController,UIPickerViewDataSource,UIPickerViewDelegate, UITextFieldDelegate {
var selectValue: String?
@IBOutlet weak var showSelectValuePickerView: UITextField!
// Array
//var team = ["Apple", "Banana", "Tomato", "Corn", "Bean", "Orange", "Mango", "Mangoteen"]
var team: [AnyObject] = []
//Function getValue from database
func getvalue() -> Void {
//get the values from sql/Json
let url = NSURL(string: "http://www.test.com/myWebService/getteamPickView.php")
let data = NSData(contentsOf: url! as URL)
var jsonResponse = try! JSONSerialization.jsonObject(with: data! as Data, options: JSONSerialization.ReadingOptions.mutableContainers) as! NSArray
jsonResponse = jsonResponse.reversed() as NSArray
reloadInputViews()
print("jsonResponse ==> \(jsonResponse)")
for candidate in jsonResponse {
if let cdict = candidate as? NSDictionary {
//fullName is the column name in sql/json
let names = cdict["NameTeam"]
self.selectValue?.append(((names! as AnyObject) as! String))
print("Names ==> \(String(describing: names))")
}//if
}//for
}//getvalue
// Picker View Function
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return self.team.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
let titleRow = (team[row] )
return titleRow as? String
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
if team.count > 0 && team.count >= row{
self.showSelectValuePickerView.text = self.team[row] as? String
self.showSelectValuePickerView.isHidden = true
}
}
}