私はセルの複数の表現を持っていたアプリの1つでそれを使用しました。境界線のあるセル、追加のボタンのあるセル、テクスチャ付きの画像のあるセルがあり、クリックするだけでそれらを変更する必要がありましたボタンの
これが私が使用したコードの一部です
//CustomCell.h
@interface CustomCell : UIView
//CustomCell.m
@implementation CustomCell
- (void)drawRect:(CGRect)rect
{
//Draw the normal images on the cell
}
@end
そして、ボーダー付きのカスタムセルの場合
//CellWithBorder.h
@interface CellWithBorder : CustomCell
{
CustomCell *aCell;
}
//CellWithBorder.m
@implementation CellWithBorder
- (void)drawRect:(CGRect)rect
{
//Draw the border
//inset the rect to draw the original cell
CGRect insetRect = CGRectInset(rect, 10, 10);
[aCell drawRect:insetRect];
}
今私のView Controllerで、私は次のことをします
CustomCell *cell = [[CustomCell alloc] init];
CellWithBorder *cellWithBorder = [[CellWithBorder alloc] initWithCell:cell];
後で別のセルに切り替えたい場合は、そうします
CellWithTexture *cellWithBorder = [[CellWithTexture alloc] initWithCell:cellWithBorder.cell];