セルをお気に入りにするための UIButton を含むカスタム UITableViewCell クラスがあります。ユーザーがボタンをタップすると、「お気に入り」状態が切り替わります。次のコードはこれを行うための正しいアプローチですか、それとも UIButton の Draw メソッドをオーバーライドし、SetNeedsDisplay を呼び出して再描画をトリガーする必要がありますか?
internal class HappyCell : UITableViewCell
{
private bool _favorite;
private UIButton _button;
public bool Favorite {
get { return _favorite; }
private set {
_favorite = value;
if (_button != null) {
_button.SetImage (_favorite ? FavImage : FavedImage, UIControlState.Normal);
}
}
}