gpt4 book ai didi

swift - UIPicker 选择显示为白色

转载 作者:行者123 更新时间:2023-11-28 07:01:16 25 4
gpt4 key购买 nike

我在实现 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]
}

谢谢,

最佳答案

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

尝试在 viewWillAppear() 而不是 viewDidLoad() 中完成。

也有可能是因为你选择了没有动画的组件,导致组件没有正常更新。在显示 View 之前,您应该为动画传递 false,但如果选择器已经对用户可见,则传递 true

关于swift - UIPicker 选择显示为白色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31982762/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com