gpt4 book ai didi

iOS 10.3 UISegmentedControl setTitleTextAttributes 崩溃

转载 作者:搜寻专家 更新时间:2023-11-01 06:34:21 24 4
gpt4 key购买 nike

iOS 10.3 在 UISegmentedControlsetTitleTextAttributes 方法上崩溃。

问题:

  1. 崩溃的原因是什么?
  2. 解决方案是什么?

注意:已将此问题报告给苹果,但尚未收到他们的消息。 https://openradar.appspot.com/31448227

示例代码:

class ViewController: UIViewController {

@IBOutlet private weak var segmentedControl: UISegmentedControl!

override func viewDidLoad() {
super.viewDidLoad()
//Crash!
segmentedControl.setTitleTextAttributes([UIFont.systemFont(ofSize: 14.0) : NSFontAttributeName], for: .normal)
}
}

编辑

正如@vedian 指出的那样,它应该是[key : value] 而不是相反,但是上面的代码不会在低于 10.3 的 iOS 版本上崩溃.

最佳答案

问题是你造成的,而不是 Apple。

字典的创建顺序是先是 key,然后是 value

segmentedControl.setTitleTextAttributes([NSFontAttributeName : UIFont.systemFont(ofSize: 14.0)], for: .normal)

关于iOS 10.3 UISegmentedControl setTitleTextAttributes 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43248718/

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