gpt4 book ai didi

ios - 我可以以编程方式检查 UITableViewCell 是什么样式吗?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:01:28 25 4
gpt4 key购买 nike

在计算 UITableViewCell 的高度时,如果我能说出什么 style 会很有用我的 UITableViewCell 设置为。我没有看到单元格本身的任何属性。这可能吗?

最佳答案

不,Apple 不公开 UITableViewCell 的样式属性。但是您有几个选择。

  1. 创建您自己的 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;
    }
  2. 手动将样式保存到单元格标记中。然后,您可以在设置单元格高度时检查单元格上的标签。例如:

    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    cell.tag = UITableViewCellStyleValue1;

关于ios - 我可以以编程方式检查 UITableViewCell 是什么样式吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28838905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com