【问题标题】:UIPickerView works properly in simulator, but *looks* empty on deviceUIPickerView 在模拟器中正常工作,但在设备上*看起来*为空
【发布时间】:2020-05-22 02:54:34
【问题描述】:

我有一个带有 UIPickView 的应用程序,它在模拟器中完美运行,但是当我在设备上运行该应用程序时,它显示为空。

重要提示:它只是看起来是空的,因为我仍然可以滚动它并且所选项目正在改变。

class ViewController: UIInputViewController, UIPickerViewDelegate, UIPickerViewDataSource {

  override func viewDidLoad() {
    super.viewDidLoad()

    fontPicker.delegate = self
    fontPicker.dataSource = self
    fontPicker.selectRow(0, inComponent: 0, animated: true)
  }

  let fonts: [FontFamily] = [...]

  var currentFont: FontFamily = FontFamily()

  func numberOfComponents(in pickerView: UIPickerView) -> Int {
    1
  }

  func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
    fonts.count
  }

  func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
    fonts[row].title
  }

  func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
    currentFont = fonts[row]
  }

}

【问题讨论】:

  • 请提供代码示例
  • 更改您的设备主题。

标签: ios swift uipickerview simulator


【解决方案1】:

请检查您的设备暗模式是打开还是关闭...希望能解决问题

【讨论】:

    【解决方案2】:

    最有可能发生的情况是您的文本是白色的,而背景也是白色的,所以您的项目就在那里,它们只是看起来不可见。

    您可以尝试覆盖属性标题函数并返回一个 NSAttributedString 并将其 foregroundColor 属性设置为黑色。

    或者,您可以覆盖行函数的视图,并按照您想要的方式构造和返回 UILabel 样式。

    您可以在堆栈溢出或通过 Google 快速搜索找到这些示例。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 2011-04-14
      • 1970-01-01
      • 2012-03-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多