ios - UIView 中的 "BOOL highlighted"属性而不是 UITableViewCell?

标签 ios objective-c uitableview uiview

在我阅读 Apple 的 TableViewSuite sample code 时,我发现了一些令人困惑的事情:
APLTimeZoneViewcontentView 中的 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 中实现相同的功能,您需要提供一个计算属性,以便您可以同时注释 setget与特定 @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/

相关文章:

ios - Swift segue - 不鼓励在分离的 View Controller 上呈现 View Controller

ios - 通过 NavigationController 传递数据

ios - UISearchController 隐藏搜索栏

ios - 当 6 出现在 UITableView 时,如何重用这些数字背景颜色 1-5?

ios - 使用 localizable.string 自定义解析错误代码?

ios - iOS 在 Web View 中加载 html 文件时屏幕黑屏

ios - 如何在 iOS 的文档目录中保存带有唯一标签的文件?

ios - 从 UITableViewCell 调用 ViewController 中的函数

ios - 如何重构UITableViewCell配置代码?

iphone - MKReverseGeocoder 委托(delegate)方法是否在单独的线程上工作?