Ios 更新UITableViewCell子类布局
如果我有一个Ios 更新UITableViewCell子类布局,ios,objective-c,cocoa-touch,uitableview,Ios,Objective C,Cocoa Touch,Uitableview,如果我有一个UITableViewCellSubclass,它可以根据TypeA或TypeB改变布局 我是否应该有一个init是[UITableViewCellSubclass initWithType:type],并且每当类型更改时,我调用[tableView重新加载RowsatindeXPath:indexPathForUITableViewCellSubclass] 或 我跳过了自定义初始化,实现了-layoutSubviews和-setType:,每当我需要更改单元格的类型时,我都会通过
UITableViewCellSubclass
,它可以根据TypeA
或TypeB
改变布局
我是否应该有一个init是[UITableViewCellSubclass initWithType:type]
,并且每当类型更改时,我调用[tableView重新加载RowsatindeXPath:indexPathForUITableViewCellSubclass]
或
我跳过了自定义初始化,实现了-layoutSubviews
和-setType:
,每当我需要更改单元格的类型时,我都会通过调用[tableView cellForRowAtIndexPath:indexPath]
然后调用[CellSetType: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;
}
}
编辑:我应该澄清,类型更改实际上并没有改变很多。只是更改一个指示电池类型的图像。为什么要经历这些麻烦?为什么不创建两个不同的类并在CFIAP中将正确的类出列呢?如果它们共享很多功能,就让它们从基类继承。我应该澄清,类型更改实际上并没有改变很多。只是更改一个指示单元格类型的图像。我认为子类化在这里更合适,正如上面所建议的那样-您需要将不同的代码挂在某个地方,因此为什么不以整洁的方式进行操作?单元格需要知道绘制/配置/设置特定类型的单元格的类型。我如何在
表格视图:cellforrowatinexpath:
中设置它,这取决于它应该显示TypeA
还是TypeB
?