Ich habe eine benutzerdefinierte Zelle erstellt. Ich habe eine Reihe von Wörterbüchern. Für die Wörterbuchwerte muss ich UILable
s erstellen. Jede Zelle kann eine unterschiedliche Anzahl von UILabel
s enthalten. Also in meiner Gewohnheit UITableViewCell
Klasse habe ich so getan.UITableView Zeilenhöhe nicht ändern
- (void)generateCell {
BOOL isLandscape = UIInterfaceOrientationIsLandscape(vc.interfaceOrientation);
for (int i = 0; i < [orderMap count]; i++) {
UILabel *lbl = [[UILabel alloc] init];
[lbl setTextColor:[UIColor blueColor]];
[lbl setBackgroundColor:[UIColor yellowColor]];
lbl.tag = [[orderMap objectAtIndex:i] intValue];
[lbl setNumberOfLines:0];
[self.contentView addSubview:lbl];
[lbl setTranslatesAutoresizingMaskIntoConstraints:false];
}
if (isLandscape) {
}
else {
[self setConstraintsForPortrait];
}
}
- (void)setConstraintsForPortrait {
double currentUsedWidth = 0;
double relativeWidthLimit = 1;
int reservedPaddingSpace = 20;
int usableScreenWidthPts = 0;
int xPositionStartingPoint = 15;
int xPosition = xPositionStartingPoint;
int yPosition = INDIVIDUAL_PADDING_PTS;
int fieldCounter = 0;
UIView *previousView;
for (UIView *vw in [self.contentView subviews]) {
NSLayoutConstraint *leading = [NSLayoutConstraint constraintWithItem:vw attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeLeading multiplier:1.0 constant:(xPosition + INDIVIDUAL_PADDING_PTS)];
NSLayoutConstraint *top;
if (previousView == nil) {
top = [NSLayoutConstraint constraintWithItem:vw attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1.0 constant:INDIVIDUAL_PADDING_PTS];
}
else {
top = [NSLayoutConstraint constraintWithItem:vw attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:previousView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:INDIVIDUAL_PADDING_PTS];
}
NSLayoutConstraint *trailing = [NSLayoutConstraint constraintWithItem:vw attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:INDIVIDUAL_PADDING_PTS];
if (fieldCounter >= [orderMap count]) {
NSLayoutConstraint *bottom = [NSLayoutConstraint constraintWithItem:vw attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:INDIVIDUAL_PADDING_PTS];
[self.contentView addConstraint:bottom];
}
[self.contentView addConstraint:leading];
[self.contentView addConstraint:top];
[self.contentView addConstraint:trailing];
previousView = vw;
}
}
Und in meiner UIViewController
viewDidLoad
Methode Ich habe dies getan.
UINib *nib = [UINib nibWithNibName:@"TableViewCell" bundle:[NSBundle mainBundle]];
[self.tbl registerNib:nib forCellReuseIdentifier:metadataListTableIdentifier];
self.tbl.estimatedRowHeight = 200;
self.tbl.rowHeight = UITableViewAutomaticDimension;
[self.tbl reloadData];
Warum ändert sich die Zellenhöhe nicht? Bitte hilf mir. Dank
ich es in viewDidLoad gesetzt haben –
noch können Sie versuchen, so zu setzen, weil es nicht in der Art und Weise arbeiten Sie –
gesetzt haben, bemerkte ich diese 2 Zeilen und hinzugefügt, um diese Teilnehmer. Aber keine Wirkung. immer noch gleich :( –