我在Swift中几乎是新人,我在UIPickerView
遇到了麻烦。问题是:
当我把物品放入拣货员时,我成功地做了,我可以选择。一切都很完美但我不知道为什么当我喜欢一两件他们没有出现的东西时,我不得不将它拖了一段时间才能看到它,而且它已被选中但问题是我不能看到它:(
这是我的代码:
class LoginViewController: UIViewController,UIPickerViewDataSource,UIPickerViewDelegate{
@IBOutlet var pickerCol: UIPickerView!
@IBOutlet var labelCol: UILabel!
@IBOutlet var textUsuario: UITextField!
@IBOutlet var textPassword: UITextField!
let defaults = NSUserDefaults.standardUserDefaults()
var picker = UIPickerView()
var NumberOfRows = 0
var NamesArray = [String]()
var IdArray = [String]()
var numero = 0
var col : String = ""
override func viewDidLoad() {
pickerCol.delegate = self
pickerCol.dataSource = self
parseJSON()
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func parseJSON(){
let parameters = [
"opcion": "listar_clientes",
"opci_codi" : "320"
]
Alamofire.request(.POST, "http://desarrollo.educalinks.com.ec/mobile/main.php", parameters: parameters).responseJSON { response in
let JSON1 = (response.result.value)
let result = JSON1!["result"] as! NSArray
let dataExample : NSData = NSKeyedArchiver.archivedDataWithRootObject(JSON1!)
NSLog("\(JSON1)")
NSLog("\(result.count)")
for i in 0..<result.count{
let id = result[i]["id"] as AnyObject? as? Int
let texto = result[i]["texto"] as AnyObject? as? String
var idcole = String(id)
self.NamesArray.append(texto!)
self.IdArray.append(idcole)
self.NumberOfRows = self.NamesArray.count
}
}
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int{
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int{
return NumberOfRows
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
labelCol.text=NamesArray[row]
col = IdArray[row]
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if(NamesArray.count != 0){
return NamesArray[row]
}
return nil
}
我一直在努力弄清楚为什么会这样。在此之前,我有10个项目的选择器,它通常显示。但有两个项目没有。我很感激帮助。
答案 0 :(得分:2)
你应该在for循环之后调用pickerCol.reloadAllComponents()
。