Chr*_*ams 2 objective-c uitableview ios
在计算UITableViewCell的高度时,如果我可以告诉我的UITableViewCell设置的样式,那将非常有用.我没有在单元格本身看到任何属性.这可能吗?
不,Apple没有公开UITableViewCell的样式属性.但是你有几个选择.
创建自己的子类,UITableViewCell在调用initWithStyle时将样式保存到属性.
@property UITableViewCellStyle cellStyle;
// ...
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.cellStyle = style;
}
return self;
}
Run Code Online (Sandbox Code Playgroud)手动将样式保存到单元格标记.然后,您可以在设置单元格高度时检查单元格上的标记.例如:
UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
cell.tag = UITableViewCellStyleValue1;
Run Code Online (Sandbox Code Playgroud)