【问题标题】:Dynamic type notification is not getting triggered未触发动态类型通知
【发布时间】:2014-06-06 20:43:55
【问题描述】:

我目前正在使用 Swift 进行开发,但遇到了动态类型的问题。我已经设置了这个代码

import Foundation
import UIKit

class ExerciseController :UIViewController, UITableViewDataSource, UITableViewDelegate {

  @IBOutlet var exerciseTableView :UITableView

  override func viewDidLoad() {
    super.viewDidLoad()
  }

  override func viewWillAppear(animated: Bool)  {
    NSNotificationCenter.defaultCenter().addObserver(self, selector: "reload", name: UIContentSizeCategoryDidChangeNotification, object: nil)
  }

  override func viewWillDisappear(animated: Bool) {
    NSNotificationCenter.defaultCenter().removeObserver(self, name: UIContentSizeCategoryDidChangeNotification, object: nil)
  }

  func reload() {
    println("reload")
  }

  func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
    return 1
  }

  func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
    return 1
  }

  func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
    let cellIdentifier = "ExerciseCell"
    var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? UITableViewCell
    if !cell {
      cell = UITableViewCell(style: .Default, reuseIdentifier: cellIdentifier)
    }
    cell!.textLabel.text = "Hello"
    cell!.textLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline)
    return cell
  }
}

我运行我的应用程序,然后转到“设置”应用程序来修改文本大小,但通知选择器没有被调用并且不知道为什么。提前感谢您解决此问题,感谢所有帮助

*以前在 viewDidiLoad 和 deinit 上设置的通知观察者,但它也不起作用

更新 #1

我用键盘通知尝试了同样的事情,它确实有效。这意味着应用程序在完成时无法识别文本大小何时发生变化

【问题讨论】:

  • 在黑暗中拍摄,试试@objc(reload) func reload() {
  • 对不起,它不起作用。它似乎不是选择器,而是应用程序没有收到有关文本大小操作的通知
  • 我能够在 XCode 6 中复制你的问题。然后我在一个实际的单元上尝试了它,它工作正常,所以它一定是 XCode 中的一个错误,稍后会修复。跨度>
  • @AJ_1310 我知道已经有一段时间了,但请看下面的更新:-)

标签: ios swift accessibility textkit


【解决方案1】:

编辑 1Apple 已确认我的错误报告并将其与另一个错误报告合并。


我做了一些测试,发现这个问题/错误只在 iOS 8 模拟器和UIContentSizeCategoryDidChangeNotification 中普遍存在。其他通知按预期工作,UIContentSizeCategoryDidChangeNotification 在 iOS 7 模拟器中按预期工作。我已经在雷达中提交了一份错误报告。希望这可以澄清在不久的将来遇到此问题的人。

编辑 2

这个问题现在似乎已经修复了。此外,来自 Big Nerd Ranch 的this library 确实简化了设置动态类型的整个过程。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-30
    • 2018-05-04
    相关资源
    最近更新 更多