UIPicker选择显示为白色

时间:2015-08-13 08:05:33

标签: swift uipickerview

我在实施UIPicker时遇到了一些麻烦。 当我查看它时,一些行显示为白色/透明。滚动了一下然后返回后,行终于出现了。

以下是截图:

第一排保持白色

enter image description here

滚动时第二行

enter image description here

完全滚动并返回后,最终显示行

enter image description here

这是代码

// 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]
}

谢谢,

1 个答案:

答案 0 :(得分:1)

也许您过早地调用设置代码。

尝试在{% load staticfiles %} <script src="{% static 'js/highcharts.js' %}"></script> 而不是viewWillAppear()中执行此操作。

此外,可能是因为您选择没有动画的组件,组件无法正确更新。您应该在显示视图之前传递viewDidLoad()动画,但如果用户已经看到选择器,则应false