0
我已经实现了一个自定义的UITableViewCell(以编程方式)。在这里我的代码一点点:自定义和动态内容UITableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
// Here I initialize three labels with 2 vertical constraints between each other
}
return self;
}
当我启动我的应用程序可以看到:
My label 1
|-vertical constraint-|
My label 2
|-vertical constraint-|
My label 3
一切正常,当我的三个标签有文字,但他们中的一些可能没有文本和我的应用程序显示:
My label 1
|-vertical constraint-|
|-vertical constraint-|
My label 3
所以我需要删除或无法初始化相关的标签,并添加/删除的权利约束显示:
My label 1
|-vertical constraint-|
My label 3
我必须在哪里做到这一点?我不能在initWithStyle
这样做,因为我不知道如果我的文字标签有值尚未:提前
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyCustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCustomCell"];
cell.name.text = name;
cell.username.text = username;
cell.description.text = description;
return cell
}
感谢。
听起来不错。我会试试看。 –
我在哪里可以添加/更新我的约束? –
在注入模型的配置方法中。 –