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
}
感謝。
聽起來不錯。我會試試看。 –
我在哪裏可以添加/更新我的約束? –
在注入模型的配置方法中。 –