如何使用Rx和嵌套单元格视图突出显示tableView单元格?

问题描述 投票:1回答:1

我有一个cell结构,看起来像这样:

enter image description here

contentViewbackgroundColor tableView具有相同的background(蓝色),并且嵌套的view具有白色,周围带有cornerRadius和5p autoLayout的白色边缘,因此看起来像像分隔的cells,有点像连续的分隔的buttons(让我知道是否需要图像)。

[每当我单击cell时,我都想用另一种颜色突出显示cell。通常,这将在storyBoard attribute inspector下的selection中完成。但这严格连接到cell,不会影响嵌套的views。我可以使views透明或完全将其删除,并且可以使用,但随后我错过了cells的错觉。

我在这里读How to add spacing between UITableViewCell您可以使用sections分隔cells。很好,但是事情是我正在使用RxSwift,如果我想要numberOfSections delegate,那么我还需要cellForRowAtnumberOfRows,并且与我的Rx tableView有点冲突。

[我尝试通过在嵌套的tag中添加view来以编程方式进行操作,如下所示:

var myView = self.contentView.viewWithTag(1) //self is cell

然后在color Rx中设置subscription

    cell?.layer.backgroundColor = UIColor.green.cgColor

但是这只是行不通。任何想法如何解决这个问题?

ios swift uitableview rx-swift
1个回答
0
投票

覆盖单元格中的方法func setSelected(_ selected: Bool, animated: Bool),并根据selected属性调整视图的方式。

或者,如果您不想覆盖此方法,则可以使用rx.methodInvoked执行此操作。

© www.soinside.com 2019 - 2024. All rights reserved.