在我阅读 Apple 的 TableViewSuite sample code
时,我发现了一些令人困惑的事情:APLTimeZoneView
是 contentView
中的 UIView的 APLTimeZoneCell
.但是,有一个属性名为
@property (nonatomic, getter=isHighlighted) BOOL highlighted
在
APLTimeZoneView
, and obviously the custom setter of the property is getting called when ever a row is selected.我的问题是,为什么
APLTimeZoneView
中突出显示的属性?而不是 APLTimeZoneCell
?我检查了 API 文档,似乎 UIView
中没有这样的属性, 仅在 UITableViewCell
.为什么要调用 setter 来设置 highlighted
to true whenever a row is selected ?
最佳答案
在 Table View Programming Guide ,有一个非常小的注释说:
The content is selected automatically if the subview implements (if appropriate) the accessor methods for the highlighted property.
备注 :要在 Swift 中实现相同的功能,您需要提供一个计算属性,以便您可以同时注释
set
和 get
与特定 @objc
名称:private var _highlighted: Bool = false
var highlighted: Bool {
@objc(isHighlighted) get { return _highlighted }
@objc(setHighlighted:) set {
_highlighted = newValue
// Now configure the view based on the new value...
}
}
关于ios - UIView 中的 "BOOL highlighted"属性而不是 UITableViewCell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34648014/