如果我有一个UITableViewCellSubclass可以改变布局,具体取决于它是TypeA还是TypeB.
我是否应该有一个 init[UITableViewCellSubclass initWithType:type]并且每当我调用类型更改时[tableView reloadRowsAtIndexPath:indexPathForUITableViewCellSubclass]
或者
我跳过自定义初始化并实现-layoutSubviews和 a -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;
}
}
编辑:我应该澄清一下,类型更改实际上并没有改变很多。只需更改指示单元格类型的图像。