我使用的是一个SplitViewController;主节点是具有一系列RightDetail单元格的tableView,这些单元格的属性字符串是通过值设置弹出窗口的回调来设置的。
通过设置单元格的detailTextLabel的方法传回和设置的值。它在DispatchQueue.main.async中执行此操作,因为对detailTextLabel的某些更新是通过来自Network.Framework的调用完成的
奇怪的是,当弹出窗口进行更改时,对属性字符串的更改不会正确显示。在正确绘制之前,焦点必须切换到下一个表单元格。

因此,只有当焦点更改为"Flow Rate“时,才能正确渲染温度,如blow所示。

我已经单步执行了以下代码,并检查是否向self.buttonCell?.detailTextLabel?.attributedText写入了正确的值
您还会看到我添加了setNeedsLayout()和setNeedsFocusUpdate()
func setDetailValueWithUnit( to index: Int) {
/** sets the detailtext to the value as the specified index and appends units.
it does this within the main dispatchQueue as this method is called by
operationResult which is called by the statemachine.
**/
DispatchQueue.main.async {
let font = self.buttonCell?.detailTextLabel?.font
let finalString = NSMutableAttributedString(string: valueString,attributes: [.font:font!])
if let units = self.units() {
finalString.append(units)
self.buttonCell?.detailTextLabel?.attributedText = finalString
//next 2 lines experimental in an attempt to fix the attributed text not
//being consistently redendered correctly
self.buttonCell?.detailTextLabel?.setNeedsLayout()
self.buttonCell?.detailTextLabel?.setNeedsFocusUpdate()
NSLog("setDetailValueWithUnit: %d", index)
return
} else {
assert(false, "No Units found")
}
}
}发布于 2019-08-18 00:15:41
问题是你所做的是完全错误的。您永远不应该触摸单元格的文本标签字体、文本或任何其他直接类似的内容。这不是表视图的工作方式。您应该设置表的数据模型并从那里更新表,从而导致对可见单元格调用cellForRowAt:。这样,只有cellForRowAt:配置单元,一切都会很好。
https://stackoverflow.com/questions/57537822
复制相似问题