1
votes

I have a custom UITableViewCell. It has a UIView which is added to the "contentView" of the UITableViewCell. For any update, I'm redrawing that UIView by calling its "setNeedsDisplay" and implementing drawing inside "drawRect" method of the UIView.

The UITableViewCell overrides "willTransitionToState" and according to the bit mask value, asks the UIView to redraw.

Because I'm asking the UIView to redraw itself again, every time I do a "swipe to delete", I see the cell "flicker" a moment; even the text that didn't move position due to the Delete button suffers from a flicker since everything is being redrawn.

I'm aware that a possible solution is not to call "setNeedsDisplay" of the UIView from the "willTransitionToState" but instead call "setNeedsLayout" and have the UIView implement "layoutSubviews".

This is where I'm stuck at: how can I re-layout my UIView since everything inside my UIView is "drawn" (I use "drawInRect" and "drawAtPoint" methods for strings and images). There is also a string on the right side that I wanna hide when the "Delete" button appears (like in the Messages app in iPhone).

How can I do this by doing re-layout instead of re-draw?

Thank you!!!

1

1 Answers

2
votes

I think there's an issue with your approach. Rather than draw everything, it's better to set up your subviews in an init method, or in the NIB.

In the willTransitionToState method, update whatever subviews according to the state transition.

In layoutSubviews, update each subview's origin and size as required.

Here's some detail from the willTransitionToState documentation. Although, I'm sure you'd have seen this already:

Subclasses of UITableViewCell can implement this method to animate additional changes to a cell when it is changing state. UITableViewCell calls this method whenever a cell transitions between states, such as from a normal state (the default) to editing mode. The custom cell can set up and position any new views that appear with the new state. The cell then receives a layoutSubviews message (UIView) in which it can position these new views in their final locations for the new state. Subclasses must always call super when overriding this method.