问题描述:

I have a UITableView and I am having an issue with whenever I try to click on the Cell. When the cell is highlighted it puts some test on top of the text that is already on the cell make the text on the cell hard to read. This only happens while I have the cell highlighted.

Please help me with this issue.

Thanks

网友答案:

I had a similar problem and then realised that I wasn't using the cell dequeuing thing properly and what had happened is that every time the cell is reused a new UIlabel was added and the text from the datasource set to that, but the UILabels from the previous time the cell was showing were still there. But you only see them when the cell is highlighted because when it's not highlighted the background is not clear, but when the cell is highlighted then the UIlabels become clear and you see the other UIlabels that are behind it.

It's quite serious as everytime cell's are dequeued (ie everytime you scroll on the tableview) all of the subviews you've added a duplicated. And it increases memory usage severely.

To fix I used the code from the apple docs on customizing table cells. You have to use tags to retrieve the subviews if the cell is dequeued.: http://developer.apple.com/iphone/library/documentation/userexperience/conceptual/TableView_iPhone/TableViewCells/TableViewCells.html#//apple_ref/doc/uid/TP40007451-CH7-SW15

相关阅读:
Top