UIPicker 选择显示为白色
UIPicker selection appears white
我在实现 UIPicker 时遇到了一些问题。
当我查看它时,出现了一些行 white/transparent。稍微滚动并返回后,该行终于出现了。
截图如下:
第一行保持白色
在第二行上滚动时也是如此
行在完全滚动并返回后终于出现
这是代码
// reinitializing array to nil
pickerContentArray = []
for i in 0..<specialitiesList.count {
pickerContentArray.append(specialitiesList[i]["name"] as! String)
}
picker.reloadAllComponents()
picker.selectRow(0, inComponent: 0, animated: false)
//MARK: - Delegates and data sources
//MARK: Data Sources
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerContentArray.count
}
func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView!) -> UIView
{
var pickerLabel = UILabel()
pickerLabel.textColor = UIColor.blackColor()
if pushedButton == "Speciality" {
pickerLabel.text = specialitiesList[row]["name"] as? String
pickerLabel.font = UIFont(name: "Helvetica", size: 12)
} else if pushedButton == "Status" {
pickerLabel.text = statusList[row]
pickerLabel.font = UIFont(name: "Helvetica", size: 16)
} else if pushedButton == "City" {
pickerLabel.text = citiesList[row]["name"] as? String
pickerLabel.font = UIFont(name: "Helvetica", size: 16)
}
pickerLabel.textAlignment = NSTextAlignment.Center
return pickerLabel
}
//MARK: Delegates
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
return pickerContentArray[row]
}
谢谢,
也许您调用设置代码的时间过早。
尝试在 viewWillAppear()
而不是 viewDidLoad()
中完成。
另外,可能是因为你select组件没有动画,所以组件没有正常更新。在显示视图之前,您应该为动画传递 false
,但如果用户已经看到选择器,则应传递 true
。
我在实现 UIPicker 时遇到了一些问题。 当我查看它时,出现了一些行 white/transparent。稍微滚动并返回后,该行终于出现了。
截图如下:
第一行保持白色
在第二行上滚动时也是如此
行在完全滚动并返回后终于出现
这是代码
// reinitializing array to nil
pickerContentArray = []
for i in 0..<specialitiesList.count {
pickerContentArray.append(specialitiesList[i]["name"] as! String)
}
picker.reloadAllComponents()
picker.selectRow(0, inComponent: 0, animated: false)
//MARK: - Delegates and data sources
//MARK: Data Sources
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerContentArray.count
}
func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView!) -> UIView
{
var pickerLabel = UILabel()
pickerLabel.textColor = UIColor.blackColor()
if pushedButton == "Speciality" {
pickerLabel.text = specialitiesList[row]["name"] as? String
pickerLabel.font = UIFont(name: "Helvetica", size: 12)
} else if pushedButton == "Status" {
pickerLabel.text = statusList[row]
pickerLabel.font = UIFont(name: "Helvetica", size: 16)
} else if pushedButton == "City" {
pickerLabel.text = citiesList[row]["name"] as? String
pickerLabel.font = UIFont(name: "Helvetica", size: 16)
}
pickerLabel.textAlignment = NSTextAlignment.Center
return pickerLabel
}
//MARK: Delegates
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String! {
return pickerContentArray[row]
}
谢谢,
也许您调用设置代码的时间过早。
尝试在 viewWillAppear()
而不是 viewDidLoad()
中完成。
另外,可能是因为你select组件没有动画,所以组件没有正常更新。在显示视图之前,您应该为动画传递 false
,但如果用户已经看到选择器,则应传递 true
。