またはUITableViewCellSubclass
に応じてレイアウトを変更できる がある場合。TypeA
TypeB
私は初期化を持っているべきであり[UITableViewCellSubclass initWithType:type]
、型が変わるたびに呼び出す必要があります[tableView reloadRowsAtIndexPath:indexPathForUITableViewCellSubclass]
また
カスタムの初期化と実装をスキップし-layoutSubviews
、セルのタイプを変更する必要があるときはいつでも、呼び出してから呼び出す-setType:
ことでセルへの参照を取得します[tableView cellForRowAtIndexPath:indexPath]
[cell setType:TypeB]
- (void)setType:(Type)type {
if (type == _type) return;
_type == type;
[self setNeedsLayout];
}
- (void)layoutSubviews {
[super layoutSubviews];
if (self.type == TypeA) {
CGRect frame = foo;
thing.frame = frame;
}
if (self.type == TypeB) {
CGRect frame = bar;
thing.frame = frame;
}
}
編集:タイプの変更が実際にはあまり変更されていないことを明確にする必要があります。細胞がどのタイプであるかを示す画像を変更するだけです。