Using a CALayer in UITableViewCell
Posted
by Brian
on Stack Overflow
See other posts from Stack Overflow
or by Brian
Published on 2010-03-26T19:13:21Z
Indexed on
2010/04/02
12:23 UTC
Read the original article
Hit count: 471
On each cell of my table view I want to have a bar that the user can slide out from the right. On the bar I plan to have icons. So, to do this I subclassed UITableViewCell. On the cell I have implemented drawRect and in there I have already drawn a gradient and background color on the cell. From there, I can create a CALayer, give it a frame & background color, and add it as a sub layer to the Views subLayers array. I can do all that and it will display my layer on each UITableViewCell.
I have added touch events to the cell so I can detect when the user touches the cell and for testing I have made it so when the user swipes, my CALayer gets wider. But the issue is, when the UITableView scrolls and reuses a cell whose CALayer has been widened, it doesn't recreate the CALayer. I have tried
[myLayer setNeedsDisplay]
and used the drawLayer:inContext method of its delegate and it doesn't get called. I have also tried telling call setNeedsDisplay on the cell in my UITableViewController hoping that that will cause a redraw, but it doesn't work.
I'm not sure what I'm missing. I am new to CoreGraphics & CoreAnimation. I have read through the CoreAnimation Developers Guide, but I'm assuming I missing something. Any help would be great.
© Stack Overflow or respective owner