【发布时间】: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