gpt4 book ai didi

ios - UIPickerView 不重用以前的组件 View

转载 作者:行者123 更新时间:2023-11-28 08:20:22 25 4
gpt4 key购买 nike

我需要更改 UIPickerView 的字体,我正在使用委托(delegate)方法,如下所示。

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView
{
var pickerLabel = view as? UILabel;

if (pickerLabel == nil)
{
pickerLabel = UILabel()

pickerLabel?.font = UIFont(name: (pickerLabel?.font.fontName)!, size: 15)
pickerLabel?.textAlignment = NSTextAlignment.center
}

pickerLabel?.text = myData[row]

return pickerLabel!
}

据我了解documentation ,一旦我创建了 UILabel View ,它们就应该被重用。但是,“ View ”参数始终为零。每次我旋转选择器时,它都会创建一个新的 UILabel。这似乎效率低下并且破坏了具有“重用”参数的目标。

这是一个错误还是我误解了它应该如何工作?

谢谢,

朱利安

最佳答案

是的,这是一个 iOS 系统错误。即使在 iOS 10.2 上也没有修复。查看相关问题:Reusing view in UIPickerView with iOS 7

关于ios - UIPickerView 不重用以前的组件 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41503767/

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